Add new sample - CustomPropertyAnimationDemo

This commit is contained in:
Rolf Bjarne Kvinge 2012-04-26 23:49:50 +02:00
Родитель e0c74261c9
Коммит 6d9e3da66a
12 изменённых файлов: 309 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,144 @@
using System;
using System.Drawing;
using MonoTouch.CoreAnimation;
using MonoTouch.CoreGraphics;
using MonoTouch.Foundation;
using MonoTouch.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 UIViewController ();
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 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);
PointF centerPoint = new PointF (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 RectangleF (centerPoint.X - (float) Radius,
centerPoint.Y - (float) Radius,
(float) Radius * 2,
(float) Radius * 2));
// Inner circle
context.AddEllipseInRect (new RectangleF (centerPoint.X - (float) innerRadius,
centerPoint.Y - (float) innerRadius,
(float) innerRadius * 2,
(float) innerRadius * 2));
// Fill in circle
context.SetFillColor (Color);
context.SetShadowWithColor (SizeF.Empty, 10.0f, glowColor);
context.EOFillPath();
}
}
}

Просмотреть файл

@ -0,0 +1,85 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">iPhoneSimulator</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}</ProjectGuid>
<ProjectTypeGuids>{6BC8ED88-2882-458C-8E55-DFD12B67127B};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Exe</OutputType>
<RootNamespace>CustomPropertyAnimation</RootNamespace>
<AssemblyName>CustomPropertyAnimation</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhoneSimulator' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchDebug>true</MtouchDebug>
<MtouchProfiling>true</MtouchProfiling>
<MtouchLink>None</MtouchLink>
<MtouchI18n />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhoneSimulator' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhoneSimulator\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<MtouchLink>None</MtouchLink>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|iPhone' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Debug</OutputPath>
<DefineConstants>DEBUG;</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
<MtouchDebug>true</MtouchDebug>
<MtouchProfiling>true</MtouchProfiling>
<MtouchI18n />
<MtouchExtraArgs>-v -v -v --keeptemp</MtouchExtraArgs>
<IpaPackageName />
<CrashReportingApiKey />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|iPhone' ">
<DebugType>none</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\iPhone\Release</OutputPath>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<ConsolePause>false</ConsolePause>
<CodesignKey>iPhone Developer</CodesignKey>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Xml" />
<Reference Include="System.Core" />
<Reference Include="monotouch" />
</ItemGroup>
<ItemGroup>
<None Include="Info.plist" />
</ItemGroup>
<ItemGroup>
<Compile Include="AppDelegate.cs" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Content Include="icons\114_icon.png" />
<Content Include="icons\144_icon.png" />
<Content Include="icons\29_icon.png" />
<Content Include="icons\50_icon.png" />
<Content Include="icons\57_icon.png" />
<Content Include="icons\58_icon.png" />
<Content Include="icons\72_icon.png" />
</ItemGroup>
</Project>

Просмотреть файл

@ -0,0 +1,26 @@

Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CustomPropertyAnimation", "CustomPropertyAnimation.csproj", "{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|iPhoneSimulator = Debug|iPhoneSimulator
Release|iPhoneSimulator = Release|iPhoneSimulator
Debug|iPhone = Debug|iPhone
Release|iPhone = Release|iPhone
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhone.ActiveCfg = Debug|iPhone
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhone.Build.0 = Debug|iPhone
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhoneSimulator.ActiveCfg = Debug|iPhoneSimulator
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Debug|iPhoneSimulator.Build.0 = Debug|iPhoneSimulator
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhone.ActiveCfg = Release|iPhone
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhone.Build.0 = Release|iPhone
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhoneSimulator.ActiveCfg = Release|iPhoneSimulator
{C27E84DD-CFA2-4136-8C63-07F4AF75E91F}.Release|iPhoneSimulator.Build.0 = Release|iPhoneSimulator
EndGlobalSection
GlobalSection(MonoDevelopProperties) = preSolution
StartupItem = CustomPropertyAnimation.csproj
EndGlobalSection
EndGlobal

Просмотреть файл

@ -0,0 +1,43 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDisplayName</key>
<string>CustomPropertyAnimation</string>
<key>CFBundleIconFiles</key>
<array>
<string>icons/57_icon.png</string>
<string>icons/114_icon.png</string>
<string>icons/72_icon.png</string>
<string>icons/144_icon.png</string>
<string>icons/29_icon.png</string>
<string>icons/58_icon.png</string>
<string>icons/50_icon.png</string>
</array>
<key>CFBundleIdentifier</key>
<string>com.xamarin.custompropertyanimation</string>
<key>CFBundleVersion</key>
<string>1.0</string>
<key>MinimumOSVersion</key>
<string>4.3</string>
<key>UIDeviceFamily</key>
<array>
<integer>1</integer>
<integer>2</integer>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
<key>UISupportedInterfaceOrientations~ipad</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
<string>UIInterfaceOrientationPortraitUpsideDown</string>
<string>UIInterfaceOrientationLandscapeLeft</string>
<string>UIInterfaceOrientationLandscapeRight</string>
</array>
</dict>
</plist>

Просмотреть файл

@ -0,0 +1,11 @@
CustomPropertyAnimation
=======================
This sample illustrates how to animate custom properties in a CALayer.
Note that this sample requires at least MonoTouch 5.3.3
Authors
-------
Rolf Bjarne Kvinge

Двоичные данные
CustomPropertyAnimation/icons/114_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 20 KiB

Двоичные данные
CustomPropertyAnimation/icons/144_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 27 KiB

Двоичные данные
CustomPropertyAnimation/icons/29_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 2.9 KiB

Двоичные данные
CustomPropertyAnimation/icons/50_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 5.8 KiB

Двоичные данные
CustomPropertyAnimation/icons/57_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.1 KiB

Двоичные данные
CustomPropertyAnimation/icons/58_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 7.3 KiB

Двоичные данные
CustomPropertyAnimation/icons/72_icon.png Normal file

Двоичный файл не отображается.

После

Ширина:  |  Высота:  |  Размер: 10 KiB