mig*_*las 4 viewwillappear uiinterfaceorientation ios uistatusbar
我需要根据方向更改视图的图像背景.为此,我使用statusBarOrientation方法viewWillAppear:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
if (UIInterfaceOrientationIsPortrait(currentOrientation)) {
NSLog(@"PORTRAIT");
} else if (UIInterfaceOrientationIsLandscape(currentOrientation)) {
NSLog(@"LANDSCAPE");
}
}
Run Code Online (Sandbox Code Playgroud)
问题是控制台总是显示PORTRAIT,即使iPad处于横向模式.相同的代码viewDidAppear工作正常,但为时已晚,用户可以看到图像的变化.这让我觉得statusBarOrientation的正确状态仍然不可用viewWillAppear,但我已经读过其他一些问题,这段代码应该在那里工作.
Min*_*bil 12
尝试
int type = [[UIDevice currentDevice] orientation];
if (type == 1) {
NSLog(@"portrait default");
}else if(type ==2){
NSLog(@"portrait upside");
}else if(type ==3){
NSLog(@"Landscape right");
}else if(type ==4){
NSLog(@"Landscape left");
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
5137 次 |
| 最近记录: |