CAShapeLayer에서 CGColor fillColor 속성에 애니메이션을 적용하려고합니다. 다음 구문을 사용하여 Objective-C를 사용하여 올바르게 작동하도록 할 수 있습니다.Monotouch를 사용할 때 어떻게 CGObject를 NSObject로 변환합니까?
- (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 등을 시도했지만 찾지 못했습니다. 시작과 끝 값을 정확하게 픽업 할 애니메이션을 얻는 방법.
CGColor를 애니메이션의 NSObject로 제공하는 적절한 방법은 무엇입니까?
감사합니다.
굉장! 그건 내 간단한 예제를 위해 작동, 그것은 내 전체 응용 프로그램에 대한 아니지만 적어도 지금은 * can * can animate the color! 감사 –