Skip to content
This repository was archived by the owner on Apr 29, 2024. It is now read-only.

Commit 6d9e3da

Browse files
committed
Add new sample - CustomPropertyAnimationDemo
1 parent e0c7426 commit 6d9e3da

12 files changed

+309
-0
lines changed
+144
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
using System;
2+
using System.Drawing;
3+
4+
using MonoTouch.CoreAnimation;
5+
using MonoTouch.CoreGraphics;
6+
using MonoTouch.Foundation;
7+
using MonoTouch.UIKit;
8+
9+
namespace CustomPropertyAnimation
10+
{
11+
[Register ("AppDelegate")]
12+
public partial class AppDelegate : UIApplicationDelegate
13+
{
14+
UIWindow window;
15+
UIViewController vc;
16+
CircleLayer testLayer;
17+
CABasicAnimation radiusAnimation;
18+
CABasicAnimation thicknessAnimation;
19+
CABasicAnimation colorAnimation;
20+
21+
public override bool FinishedLaunching (UIApplication app, NSDictionary options)
22+
{
23+
// create a new window instance based on the screen size
24+
window = new UIWindow (UIScreen.MainScreen.Bounds);
25+
26+
vc = new UIViewController ();
27+
vc.View.BackgroundColor = UIColor.Black;
28+
testLayer = new CircleLayer();
29+
testLayer.Color = UIColor.Green.CGColor;
30+
testLayer.Thickness = 19f;
31+
testLayer.Radius = 60f;
32+
33+
testLayer.Frame = vc.View.Layer.Bounds;
34+
vc.View.Layer.AddSublayer(testLayer);
35+
36+
testLayer.SetNeedsDisplay();
37+
38+
radiusAnimation = CABasicAnimation.FromKeyPath ("radius");
39+
radiusAnimation.Duration = 3;
40+
radiusAnimation.To = NSNumber.FromDouble (120);
41+
radiusAnimation.RepeatCount = 1000;
42+
43+
thicknessAnimation = CABasicAnimation.FromKeyPath ("thickness");
44+
thicknessAnimation.Duration = 2;
45+
thicknessAnimation.From = NSNumber.FromDouble (5);
46+
thicknessAnimation.To = NSNumber.FromDouble (38);
47+
thicknessAnimation.RepeatCount = 1000;
48+
49+
colorAnimation = CABasicAnimation.FromKeyPath ("circleColor");
50+
colorAnimation.Duration = 4;
51+
colorAnimation.To = new NSObject (UIColor.Blue.CGColor.Handle);
52+
colorAnimation.RepeatCount = 1000;
53+
54+
testLayer.AddAnimation (radiusAnimation, "radiusAnimation");
55+
testLayer.AddAnimation (thicknessAnimation, "thicknessAnimation");
56+
testLayer.AddAnimation (colorAnimation, "colorAnimation");
57+
58+
window.RootViewController = vc;
59+
// make the window visible
60+
window.MakeKeyAndVisible ();
61+
62+
return true;
63+
}
64+
65+
// This is the main entry point of the application.
66+
static void Main (string[] args)
67+
{
68+
// if you want to use a different Application Delegate class from "AppDelegate"
69+
// you can specify it here.
70+
UIApplication.Main (args, null, "AppDelegate");
71+
}
72+
}
73+
74+
public class CircleLayer : CALayer
75+
{
76+
public CircleLayer ()
77+
{
78+
}
79+
80+
[Export ("initWithLayer:")]
81+
public CircleLayer (CALayer other)
82+
: base (other)
83+
{
84+
}
85+
86+
public override void Clone (CALayer other)
87+
{
88+
CircleLayer o = (CircleLayer) other;
89+
Radius = o.Radius;
90+
Color = o.Color;
91+
Thickness = o.Thickness;
92+
base.Clone (other);
93+
}
94+
95+
[Export ("radius")]
96+
public double Radius { get; set; }
97+
98+
[Export ("thickness")]
99+
public double Thickness { get; set; }
100+
101+
[Export ("circleColor")]
102+
public CGColor Color { get; set; }
103+
104+
[Export ("needsDisplayForKey:")]
105+
static bool NeedsDisplayForKey (NSString key)
106+
{
107+
switch (key.ToString ()) {
108+
case "radius":
109+
case "thickness":
110+
case "circleColor":
111+
return true;
112+
default:
113+
return CALayer.NeedsDisplayForKey (key);
114+
}
115+
}
116+
117+
public override void DrawInContext (CGContext context)
118+
{
119+
base.DrawInContext (context);
120+
121+
// Console.WriteLine ("DrawInContext Radius: {0} Thickness: {1} Color: {2}", Radius, Thickness, Color);
122+
123+
PointF centerPoint = new PointF (this.Bounds.Width / 2, this.Bounds.Height / 2);
124+
CGColor glowColor = new UIColor (Color).ColorWithAlpha (0.85f).CGColor;
125+
double innerRadius = (Radius - Thickness) > 0 ? Radius - Thickness : 0;
126+
127+
// Outer circle
128+
context.AddEllipseInRect (new RectangleF (centerPoint.X - (float) Radius,
129+
centerPoint.Y - (float) Radius,
130+
(float) Radius * 2,
131+
(float) Radius * 2));
132+
// Inner circle
133+
context.AddEllipseInRect (new RectangleF (centerPoint.X - (float) innerRadius,
134+
centerPoint.Y - (float) innerRadius,
135+
(float) innerRadius * 2,
136+
(float) innerRadius * 2));
137+
138+
// Fill in circle
139+
context.SetFillColor (Color);
140+
context.SetShadowWithColor (SizeF.Empty, 10.0f, glowColor);
141+
context.EOFillPath();
142+
}
143+
}
144+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup>
4+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
5+
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
6+
<ProductVersion>10.0.0</ProductVersion>
7+
<SchemaVersion>2.0</SchemaVersion>
8+
<ProjectGuid>{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}</ProjectGuid>
9+
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
10+
<OutputType>Exe</OutputType>
11+
<RootNamespace>CustomPropertyAnimation</RootNamespace>
12+
<AssemblyName>CustomPropertyAnimation</AssemblyName>
13+
</PropertyGroup>
14+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
15+
<DebugSymbols>true</DebugSymbols>
16+
<DebugType>full</DebugType>
17+
<Optimize>false</Optimize>
18+
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
19+
<DefineConstants>DEBUG;</DefineConstants>
20+
<ErrorReport>prompt</ErrorReport>
21+
<WarningLevel>4</WarningLevel>
22+
<ConsolePause>false</ConsolePause>
23+
<MtouchDebug>true</MtouchDebug>
24+
<MtouchProfiling>true</MtouchProfiling>
25+
<MtouchLink>None</MtouchLink>
26+
<MtouchI18n />
27+
</PropertyGroup>
28+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
29+
<DebugType>none</DebugType>
30+
<Optimize>false</Optimize>
31+
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
32+
<ErrorReport>prompt</ErrorReport>
33+
<WarningLevel>4</WarningLevel>
34+
<ConsolePause>false</ConsolePause>
35+
<MtouchLink>None</MtouchLink>
36+
</PropertyGroup>
37+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
38+
<DebugSymbols>true</DebugSymbols>
39+
<DebugType>full</DebugType>
40+
<Optimize>false</Optimize>
41+
<OutputPath>bin\iPhone\Debug</OutputPath>
42+
<DefineConstants>DEBUG;</DefineConstants>
43+
<ErrorReport>prompt</ErrorReport>
44+
<WarningLevel>4</WarningLevel>
45+
<ConsolePause>false</ConsolePause>
46+
<CodesignKey>iPhone Developer</CodesignKey>
47+
<MtouchDebug>true</MtouchDebug>
48+
<MtouchProfiling>true</MtouchProfiling>
49+
<MtouchI18n />
50+
<MtouchExtraArgs>-v -v -v --keeptemp</MtouchExtraArgs>
51+
<IpaPackageName />
52+
<CrashReportingApiKey />
53+
</PropertyGroup>
54+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
55+
<DebugType>none</DebugType>
56+
<Optimize>false</Optimize>
57+
<OutputPath>bin\iPhone\Release</OutputPath>
58+
<ErrorReport>prompt</ErrorReport>
59+
<WarningLevel>4</WarningLevel>
60+
<ConsolePause>false</ConsolePause>
61+
<CodesignKey>iPhone Developer</CodesignKey>
62+
</PropertyGroup>
63+
<ItemGroup>
64+
<Reference Include="System" />
65+
<Reference Include="System.Xml" />
66+
<Reference Include="System.Core" />
67+
<Reference Include="monotouch" />
68+
</ItemGroup>
69+
<ItemGroup>
70+
<None Include="Info.plist" />
71+
</ItemGroup>
72+
<ItemGroup>
73+
<Compile Include="AppDelegate.cs" />
74+
</ItemGroup>
75+
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
76+
<ItemGroup>
77+
<Content Include="icons\114_icon.png" />
78+
<Content Include="icons\144_icon.png" />
79+
<Content Include="icons\29_icon.png" />
80+
<Content Include="icons\50_icon.png" />
81+
<Content Include="icons\57_icon.png" />
82+
<Content Include="icons\58_icon.png" />
83+
<Content Include="icons\72_icon.png" />
84+
</ItemGroup>
85+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 11.00
3+
# Visual Studio 2010
4+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomPropertyAnimation", "CustomPropertyAnimation.csproj", "{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}"
5+
EndProject
6+
Global
7+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
8+
Debug|iPhoneSimulator = Debug|iPhoneSimulator
9+
Release|iPhoneSimulator = Release|iPhoneSimulator
10+
Debug|iPhone = Debug|iPhone
11+
Release|iPhone = Release|iPhone
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhone.ActiveCfg = Debug|iPhone
15+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhone.Build.0 = Debug|iPhone
16+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
17+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
18+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhone.ActiveCfg = Release|iPhone
19+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhone.Build.0 = Release|iPhone
20+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
21+
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
22+
EndGlobalSection
23+
GlobalSection(MonoDevelopProperties) = preSolution
24+
StartupItem = CustomPropertyAnimation.csproj
25+
EndGlobalSection
26+
EndGlobal

CustomPropertyAnimation/Info.plist

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>CFBundleDisplayName</key>
6+
<string>CustomPropertyAnimation</string>
7+
<key>CFBundleIconFiles</key>
8+
<array>
9+
<string>icons/57_icon.png</string>
10+
<string>icons/114_icon.png</string>
11+
<string>icons/72_icon.png</string>
12+
<string>icons/144_icon.png</string>
13+
<string>icons/29_icon.png</string>
14+
<string>icons/58_icon.png</string>
15+
<string>icons/50_icon.png</string>
16+
</array>
17+
<key>CFBundleIdentifier</key>
18+
<string>com.xamarin.custompropertyanimation</string>
19+
<key>CFBundleVersion</key>
20+
<string>1.0</string>
21+
<key>MinimumOSVersion</key>
22+
<string>4.3</string>
23+
<key>UIDeviceFamily</key>
24+
<array>
25+
<integer>1</integer>
26+
<integer>2</integer>
27+
</array>
28+
<key>UISupportedInterfaceOrientations</key>
29+
<array>
30+
<string>UIInterfaceOrientationPortrait</string>
31+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
32+
<string>UIInterfaceOrientationLandscapeLeft</string>
33+
<string>UIInterfaceOrientationLandscapeRight</string>
34+
</array>
35+
<key>UISupportedInterfaceOrientations~ipad</key>
36+
<array>
37+
<string>UIInterfaceOrientationPortrait</string>
38+
<string>UIInterfaceOrientationPortraitUpsideDown</string>
39+
<string>UIInterfaceOrientationLandscapeLeft</string>
40+
<string>UIInterfaceOrientationLandscapeRight</string>
41+
</array>
42+
</dict>
43+
</plist>

CustomPropertyAnimation/README.md

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
CustomPropertyAnimation
2+
=======================
3+
4+
This sample illustrates how to animate custom properties in a CALayer.
5+
6+
Note that this sample requires at least MonoTouch 5.3.3
7+
8+
Authors
9+
-------
10+
11+
Rolf Bjarne Kvinge
19.5 KB
Loading
26.6 KB
Loading
2.94 KB
Loading
5.75 KB
Loading
7.15 KB
Loading
7.3 KB
Loading
10.1 KB
Loading

0 commit comments

Comments
 (0)