forked from xamarin/ios-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AppDelegate.cs
160 lines (132 loc) · 4.56 KB
/
AppDelegate.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
using System;
using CoreAnimation;
using CoreGraphics;
using Foundation;
using UIKit;
namespace CustomPropertyAnimation
{
[Register ("AppDelegate")]
public partial class AppDelegate : UIApplicationDelegate
{
UIWindow window;
UIViewController vc;
CircleLayer testLayer;
CABasicAnimation radiusAnimation;
CABasicAnimation thicknessAnimation;
CABasicAnimation colorAnimation;
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
{
// create a new window instance based on the screen size
window = new UIWindow (UIScreen.MainScreen.Bounds);
vc = new UIViewControllerRotation ();
vc.View.BackgroundColor = UIColor.Black;
testLayer = new CircleLayer();
testLayer.Color = UIColor.Green.CGColor;
testLayer.Thickness = 19f;
testLayer.Radius = 60f;
testLayer.Frame = vc.View.Layer.Bounds;
vc.View.Layer.AddSublayer(testLayer);
testLayer.SetNeedsDisplay();
radiusAnimation = CABasicAnimation.FromKeyPath ("radius");
radiusAnimation.Duration = 3;
radiusAnimation.To = NSNumber.FromDouble (120);
radiusAnimation.RepeatCount = 1000;
thicknessAnimation = CABasicAnimation.FromKeyPath ("thickness");
thicknessAnimation.Duration = 2;
thicknessAnimation.From = NSNumber.FromDouble (5);
thicknessAnimation.To = NSNumber.FromDouble (38);
thicknessAnimation.RepeatCount = 1000;
colorAnimation = CABasicAnimation.FromKeyPath ("circleColor");
colorAnimation.Duration = 4;
colorAnimation.To = new NSObject (UIColor.Blue.CGColor.Handle);
colorAnimation.RepeatCount = 1000;
testLayer.AddAnimation (radiusAnimation, "radiusAnimation");
testLayer.AddAnimation (thicknessAnimation, "thicknessAnimation");
testLayer.AddAnimation (colorAnimation, "colorAnimation");
window.RootViewController = vc;
// make the window visible
window.MakeKeyAndVisible ();
return true;
}
// This is the main entry point of the application.
static void Main (string[] args)
{
// if you want to use a different Application Delegate class from "AppDelegate"
// you can specify it here.
UIApplication.Main (args, null, "AppDelegate");
}
}
public class UIViewControllerRotation : UIViewController
{
public override void WillAnimateRotation (UIInterfaceOrientation toInterfaceOrientation, double duration)
{
base.WillAnimateRotation (toInterfaceOrientation, duration);
// call our helper method to position the controls
CALayer[] layers = this.View.Layer.Sublayers;
foreach (CALayer layer in layers)
{
layer.Frame = this.View.Layer.Bounds;
}
}
}
public class CircleLayer : CALayer
{
public CircleLayer ()
{
}
[Export ("initWithLayer:")]
public CircleLayer (CALayer other)
: base (other)
{
}
public override void Clone (CALayer other)
{
CircleLayer o = (CircleLayer) other;
Radius = o.Radius;
Color = o.Color;
Thickness = o.Thickness;
base.Clone (other);
}
[Export ("radius")]
public double Radius { get; set; }
[Export ("thickness")]
public double Thickness { get; set; }
[Export ("circleColor")]
public CGColor Color { get; set; }
[Export ("needsDisplayForKey:")]
static bool NeedsDisplayForKey (NSString key)
{
switch (key.ToString ()) {
case "radius":
case "thickness":
case "circleColor":
return true;
default:
return CALayer.NeedsDisplayForKey (key);
}
}
public override void DrawInContext (CGContext context)
{
base.DrawInContext (context);
// Console.WriteLine ("DrawInContext Radius: {0} Thickness: {1} Color: {2}", Radius, Thickness, Color);
//Console.WriteLine (this.Bounds.Width+" "+ this.Bounds.Height);
CGPoint centerPoint = new CGPoint (this.Bounds.Width / 2, this.Bounds.Height / 2);
CGColor glowColor = new UIColor (Color).ColorWithAlpha (0.85f).CGColor;
double innerRadius = (Radius - Thickness) > 0 ? Radius - Thickness : 0;
// Outer circle
context.AddEllipseInRect (new CGRect (centerPoint.X - (float) Radius,
centerPoint.Y - (float) Radius,
(float) Radius * 2,
(float) Radius * 2));
// Inner circle
context.AddEllipseInRect (new CGRect (centerPoint.X - (float) innerRadius,
centerPoint.Y - (float) innerRadius,
(float) innerRadius * 2,
(float) innerRadius * 2));
// Fill in circle
context.SetFillColor (Color);
context.SetShadow (CGSize.Empty, 10.0f, glowColor);
context.EOFillPath();
}
}
}