我如何动画原点?

时间:2012-08-13 11:33:56

标签: objective-c ios animation core-animation

我想基于其左上角(原点)的值来设置视图位置的动画。我试过了两次

CGPoint myPosition = CGPointMake(0, 500);
CABasicAnimation *yAnimation = [CABasicAnimation animationWithKeyPath:@"frameOrigin"];
yAnimation.toValue = [NSValue valueWithCGPoint:myPosition];

CGPoint myPosition = CGPointMake(0, 500);
CABasicAnimation *yAnimation = [CABasicAnimation animationWithKeyPath:@"origin"];
yAnimation.toValue = [NSValue valueWithCGPoint:myPosition];

没有任何作用。如何正确设置此属性的动画?

2 个答案:

答案 0 :(得分:2)

如果您只想为视图的位置设置动画,请查看UIViewAnimation并使用带有它的块。

[UIView animateWithDuration:.7
        animations:^{
           //what you would like to animate
           myView.frame = CGRectMake(myView.frame.origin.x + 100,myView.frame.origin.y + 100, myView.frame.size.width, myView.frame.size.height);
        }completion:^(BOOL finished){
          //do something when the animation finishes
        }];

答案 1 :(得分:1)

origin上没有frameOriginCALayer关键路径,如果您想为bounds属性设置动画所需的位置设置动画