0

我想要做的是左右旋转视图,同时上下移动它的位置。

这是我的代码:

CGAffineTransform leftWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-12.0));
CGAffineTransform rightWobble = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(12.0));

flyingGuy.transform = leftWobble;  // starting point

[UIView beginAnimations:@"wobble" context:flyingGuy];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:1000];
[UIView setAnimationDuration:1.3];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(wobbleEnded:finished:context:)];

flyingGuy.transform = rightWobble;
CGRect frame = flyingGuy.frame;
frame.origin.y += 10;
[flyingGuy setFrame:frame];

[UIView commitAnimations];


- (void)wobbleEnded:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context  {
    if ([finished boolValue]) {
        UIView* item = (UIView *)context;
        item.transform = CGAffineTransformIdentity;
    }
}

使用当前代码,视图大小会随着向上或向下移动而变化。有什么建议么?

4

1 回答 1

5

设置变换后不要设置或获取帧!

从文档:

警告如果该transform属性不是恒等变换,则该属性的值是未定义的,因此应该被忽略。


你应该做什么

更改center视图的属性。无论如何,您只是在更改位置,并且在应用了变换时这是安全的。

于 2012-06-11T15:27:38.087 回答