我从来没有玩过横向 iPhone,但我有一个功能完备的 iPhone 应用程序,它假设用户正在直立查看 iPhone。我想玩转手机,为此,我做了一些非常简单的事情:
我将以下代码添加到我的 View Controller 中:
-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration {
NSLog(@"WILL ROTATE TO INTERFACE ORIENTATION: %@",orientation);
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight))
tableView.frame = CGRectMake(0, 0, 480, 320);
else
tableView.frame = CGRectMake(0,73,320,390);
}
我收到 BAD_ACCESS 错误。我根本看不到 View 负载。那么,问题是什么?我该如何正确实现 willRotate 方法,以便在手机旋转时调整所有组件的大小?
最佳答案
崩溃是由这一行引起的:
NSLog(@"WILL ROTATE TO INTERFACE ORIENTATION: %@",orientation);
orientation
是一个 enum
值,因此格式说明符应该是 %i
而不是 %@
。
支持旋转的最简单方法是实现:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
为您希望支持的方向返回 YES
。不要在此方法中进行任何调整大小。使用 View struts 和 springs 来确保它们为交替旋转正确调整大小和重新定位。
关于iphone - 旋转 iPhone 并改变 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4796121/