我要做的是左右旋转视图,同时上下移动它。
这是我的代码:
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;
}
}
使用当前代码,视图大小随着向上或向下移动而改变。有什么建议吗?
答案 0 :(得分:5)
设置转换后不要设置或获取帧!
来自文档:
警告如果
transform
属性不是标识转换,则此属性的值未定义,因此应忽略。
更改视图的center
属性。您只是在改变位置,并且在应用变换时这是安全的。