CAShapeLayerでCGColorfillColorプロパティをアニメーション化しようとしています。次の構文でObjective-Cを使用すると、問題なく動作するようになります。
- (void)viewDidLoad {
[super viewDidLoad];
// Create the path
thisPath = CGPathCreateMutable();
CGPathMoveToPoint(thisPath, NULL, 100.0f, 50.0f);
CGPathAddLineToPoint(thisPath, NULL, 10.0f, 140.0f);
CGPathAddLineToPoint(thisPath, NULL, 180.0f, 140.0f);
CGPathCloseSubpath(thisPath);
// Create shape layer
shapeLayer = [CAShapeLayer layer];
shapeLayer.frame = self.view.bounds;
shapeLayer.path = thisPath;
shapeLayer.fillColor = [UIColor redColor].CGColor;
[self.view.layer addSublayer:shapeLayer];
// Add the animation
CABasicAnimation* colorAnimation = [CABasicAnimation animationWithKeyPath:@"fillColor"];
colorAnimation.duration = 4.0;
colorAnimation.repeatCount = 1e100f;
colorAnimation.autoreverses = YES;
colorAnimation.fromValue = (id) [UIColor redColor].CGColor;
colorAnimation.toValue = (id) [UIColor blueColor].CGColor;
[shapeLayer addAnimation:colorAnimation forKey:@"animateColor"];
}
これにより、期待どおりにカラーシフトがアニメートされます。これをMonotouchに移植するとき、私は次のことを試しました。
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
thisPath = new CGPath();
thisPath.MoveToPoint(100,50);
thisPath.AddLineToPoint(10,140);
thisPath.AddLineToPoint(180,140);
thisPath.CloseSubpath();
shapeLayer = new CAShapeLayer();
shapeLayer.Path = thisPath;
shapeLayer.FillColor = UIColor.Red.CGColor;
View.Layer.AddSublayer(shapeLayer);
CABasicAnimation colorAnimation = CABasicAnimation.FromKeyPath("fillColor");
colorAnimation.Duration = 4;
colorAnimation.RepeatCount = float.PositiveInfinity;
colorAnimation.AutoReverses = true;
colorAnimation.From = NSObject.FromObject(UIColor.Red.CGColor);
colorAnimation.To = NSObject.FromObject(UIColor.Blue.CGColor);
shapeLayer.AddAnimation(colorAnimation, "animateColor");
}
ただし、アニメーションは再生されません。AnimationStartedイベントが発生するため、おそらくアニメーションを実行しようとしていますが、画面に目に見える証拠が表示されません。
私はこれを一日の大部分で遊んでいて、それはCGColorからNSObjectへの変換だと思います-NSObject.FromObject、NSValue.ValueFromHandleなどを試しましたが、取得する方法が見つかりませんでした開始値と終了値を正しくピックアップするためのアニメーション。
アニメーションのNSObjectとしてCGColorを提供する適切な方法は何ですか?
ありがとう!