今日はC#でCore Animation。

ネットでみつけた「Core Animationの基礎的なところ」というのをC#に置き換えてみます。

using System;
using System.Drawing;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using MonoTouch.CoreAnimation;

namespace UIKitExample
{
    public class UIViewExample : UIViewController
    {

        public UIViewExample ()
        {
            this.View.BackgroundColor = new UIColor (1.0f, 1.0f, 1.0f, 1.0f);

            //UIViewのLayerをアニメーション
            UIView uiView = new UIView ();
            uiView.Frame = new RectangleF (0.0f, 0.0f, 100.0f, 100.0f);
            uiView.BackgroundColor = UIColor.Red;
            this.View.AddSubview (uiView);
            CABasicAnimation animation = CABasicAnimation.FromKeyPath ("position");
            uiView.Layer.Position = new PointF (250.0f, 250.0f);
            animation.From = NSValue.FromPointF (new PointF (100.0f, 100.0f));
            animation.To = NSValue.FromPointF (new PointF (250.0f, 250.0f));
            animation.Duration = 1.5d;
            animation.RepeatCount = 1.0f;
            uiView.Layer.AddAnimation (animation, "move");

            //Layerのインスタンスを追加してアニメーション
            CALayer caLayer = new CALayer ();
            caLayer.Frame = new RectangleF(0.0f,0.0f,100.0f, 100.0f);
            caLayer.BackgroundColor = UIColor.Blue.CGColor;
            CABasicAnimation animation2 = CABasicAnimation.FromKeyPath("position");
            caLayer.Position = new PointF(100.0f,100.0f);
            animation2.From = NSValue.FromPointF (new PointF (250.0f, 300.0f));
            animation2.To = NSValue.FromPointF (new PointF (100.0f, 100.0f));
            animation2.Duration = 1.5d;
            animation2.RepeatCount = 1.0f;
            caLayer.AddAnimation (animation2, "move");
            uiView.Layer.AddSublayer (caLayer);
        }
    }
}