我在我的代码中实现了这个方法,以了解何时会发生接口方向更改:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
Run Code Online (Sandbox Code Playgroud)
我依靠这个来设置我的观点.在iOS 4或5中,当方向改变时,它会被正确调用.
在iOS 4中,它也会在控制器首次加载时被调用(无论方向是否发生变化,它都会在开始时以正确的方向调用一次).
问题是我在iOS 5中注意到这种情况不再发生了.当方向改变时调用该方法,而不是在控制器最初加载时调用.这对我来说是个问题,因为我依靠它来根据方向设置初始视图放置.
任何想法为什么这种行为改变?处理这个问题的最佳方法是什么?如果在iOS 5上,我应该检查viewDidLoad中的方向,然后手动调用willRotate和didRotate方法吗?这感觉有点像黑客.
感谢您提供的任何输入.
neb*_*ebs 15
由于我时间紧迫,我不得不解决这个奇怪的行为,并在viewDidLoad中手动调用方向方法.这有点像黑客,但它到目前为止工作正常.
在viewDidLoad中我添加了这个:
if ( SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"5.0") ) {
UIInterfaceOrientation interfaceOrientation = [[UIApplication sharedApplication] statusBarOrientation];
[self willRotateToInterfaceOrientation:interfaceOrientation duration:0.2f];
}
Run Code Online (Sandbox Code Playgroud)
我已经在一个公共头文件中添加了这个:
// iOS Version Checking
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)
Run Code Online (Sandbox Code Playgroud)
我从SO的这个问题的答案得到了iOS版本检查定义.
| 归档时间: |
|
| 查看次数: |
8535 次 |
| 最近记录: |