-
Notifications
You must be signed in to change notification settings - Fork 5
/
GridSplitterRenderer.cs
61 lines (50 loc) · 1.81 KB
/
GridSplitterRenderer.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
using CoreGraphics;
using Foundation;
using GridSplitterApp.iOS.Renderer;
using GridSplitterApp.Controls;
using System.Linq;
using UIKit;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;
[assembly: ExportRenderer(typeof(GridSplitter), typeof(GridSplitterRenderer))]
namespace GridSplitterApp.iOS.Renderer
{
public class GridSplitterRenderer : VisualElementRenderer<GridSplitter>
{
private UIPanGestureRecognizer _panGestureRecognizer;
private CGPoint? _oldPt;
protected override void OnElementChanged(ElementChangedEventArgs<GridSplitter> e)
{
base.OnElementChanged(e);
_panGestureRecognizer = new UIPanGestureRecognizer(OnPanGesture) { MaximumNumberOfTouches = 1, MinimumNumberOfTouches = 1 };
if (e.NewElement == null)
{
if (_panGestureRecognizer != null)
{
RemoveGestureRecognizer(_panGestureRecognizer);
}
}
if (e.OldElement == null)
{
AddGestureRecognizer(_panGestureRecognizer);
UserInteractionEnabled = true;
}
}
public override void TouchesBegan(NSSet touches, UIEvent evt)
{
base.TouchesBegan(touches, evt);
_oldPt = (touches.First() as UITouch).LocationInView(UIApplication.SharedApplication.KeyWindow);
}
void OnPanGesture()
{
Point ptOffset = Point.Zero;
CGPoint pt = _panGestureRecognizer.LocationInView(UIApplication.SharedApplication.KeyWindow);
if (_oldPt != null)
{
ptOffset = new Point(pt.X - _oldPt.Value.X, pt.Y - _oldPt.Value.Y);
}
_oldPt = pt;
Element.UpdateGrid(ptOffset.X, ptOffset.Y);
}
}
}