1

我想根据左上角(原点)的值对视图的位置进行动画处理。我都试过了

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];

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

4

2 回答 2

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
        }];
于 2012-08-13T11:49:10.570 回答
1

a上没有路径originframeOrigin关键路径CALayer,如果要为位置设置动画,则需要为bounds属性设置动画

于 2012-08-13T11:40:40.793 回答