-
Notifications
You must be signed in to change notification settings - Fork 0
/
TouchWindow.cs
74 lines (63 loc) · 2.09 KB
/
TouchWindow.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
62
63
64
65
66
67
68
69
70
71
72
73
74
using CoreAnimation;
using CoreGraphics;
using Foundation;
using UIKit;
namespace InTheHand
{
public sealed class TouchWindow : UIWindow
{
public TouchWindow(CGRect bounds) : base(bounds)
{
}
public override void SendEvent(UIEvent evt)
{
NSSet touches = evt.AllTouches;
foreach (UITouch touch in touches)
{
switch (touch.Phase)
{
case UITouchPhase.Began:
TouchBegan(touch);
break;
case UITouchPhase.Moved:
TouchMoved(touch);
break;
case UITouchPhase.Ended:
case UITouchPhase.Cancelled:
TouchEnding(touch);
break;
}
}
base.SendEvent(evt);
}
CAShapeLayer circleLayer;
void ShowCircleAtPosition(CGPoint position)
{
circleLayer = new CAShapeLayer();
circleLayer.Position = new CGPoint(position.X - 20, position.Y - 20);
UIBezierPath startPath = UIBezierPath.FromOval(new CGRect(0, 0, 40, 40));
circleLayer.Path = startPath.CGPath;
circleLayer.FillColor = UIColor.FromRGBA(0xff, 0xff, 0xff, 0x80).CGColor;
circleLayer.StrokeColor = UIColor.FromRGBA(0x00, 0x00, 0x00, 0x80).CGColor;
circleLayer.LineWidth = 2.0f;
Layer.AddSublayer(circleLayer);
}
public void TouchBegan(UITouch touch)
{
ShowCircleAtPosition(touch.LocationInView(this));
}
public void TouchMoved(UITouch touch)
{
if (circleLayer != null)
{
CGPoint position = touch.LocationInView(this);
circleLayer.Position = new CGPoint(position.X - 30, position.Y - 30);
}
}
public void TouchEnding(UITouch touch)
{
circleLayer?.RemoveFromSuperLayer();
circleLayer = null;
}
}
}