我有一个 UIImageView 作为我的应用程序的背景图像,它就像遇险的直升机一样自动旋转。问题是,当方向自动旋转时,我的图像会到处移动,我不喜欢它。由于它是一个简单的纹理,我认为用户更愿意让它留在原来的位置,而不是自动旋转。我的意思是,我希望图像保持全屏,并且当用户旋转手机时,图像仅旋转 90 度,因此看起来图像与手机保持静态,而不是应用程序的其余部分。
最佳答案
您可以尝试在 View Controller 中实现 willAnimateRotationToInterfaceOrientation:duration:
方法,并向相反方向旋转 UIImageView
。
下面的代码是我的想法,我不能保证它会起作用:
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation duration:(NSTimeInterval)duration {
CGFloat angle = M_PI/2; // Figure out the proper angle
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
imageview.transform = CGAffineTransformMakeRotation(angle);
[UIView commitAnimations];
}
关于iphone - 如何防止图像自动旋转?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3182435/