在iPad旋转中的textfield动画
问题描述:
我开始将iPhone应用程序升级到通用应用程序,并且我有一个问题:当用户旋转iPad时,如何为两个文本框设置动画效果?在iPad旋转中的textfield动画
在肖像中,它们位于视图中间,但在景观中,我希望它们位于视图的右侧。
我该怎么做动画?
感谢,
锐
答
当界面旋转,您的视图控制器的willAnimateRotationToInterfaceOrientation:duration:
方法将被调用。它从动画块内部调用以进行旋转,因此对任何动画属性的更改都应该自动进行动画。实现应该看起来像这样:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
// Move views to the correct positions for landscape orientation
} else {
// Move views to the correct positions for portrait orientation
}
}
并且为了给textfields设置动画,我只需要传递新的位置,对吗? – 2011-03-05 17:24:43
是的,您应该能够简单地分配每个文本字段的“帧”或“中心”属性。 – Anomie 2011-03-05 17:27:19
我正在使用:usernameTextField.frame = CGRectOffset(usernameTextField.frame,384,501); 它从屏幕上消失。任何想法为什么? – 2011-03-05 19:31:47