我想基于其左上角(原点)的值来设置视图位置的动画。我试过了两次
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];
没有任何作用。如何正确设置此属性的动画?
答案 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
上没有frameOrigin
或CALayer
关键路径,如果您想为bounds
属性设置动画所需的位置设置动画