Jus*_*tin 35 iphone orientation ipad
在这种情况下我不需要指定方向,我只需要检测它,但我遇到了麻烦.我有条件代码,只能在肖像中工作,如果设备在横向,我需要做其他事情.由于deviceOrientation不一定与interfaceOrientation相同,我无法想出一种测试纵向模式的方法.
我在Google上找到的大多数教程都是强制横向或进行某种轮换的方法.我唯一想做的就是确定方向是什么.这是我的代码,它不起作用:
-(void)viewDidLoad {
    [super viewDidLoad];
    //currentOrientation is declared as UIInterfaceOrientation currentOrientation
    currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
NSLog(@"%@",currentOrientation);  // == NULL
}
Run Code Online (Sandbox Code Playgroud)
我需要有条件地确定interfaceOrientation和program的值.谢谢你的帮助!
zou*_*oul 77
你知道班上的interfaceOrientation财产UIViewController吗?
- (void) viewDidLoad {
    [super viewDidLoad];
    BOOL isPortrait = UIDeviceOrientationIsPortrait(self.interfaceOrientation);
    // now do whatever you need
}
Run Code Online (Sandbox Code Playgroud)
或者你之后[[UIDevice currentDevice] orientation]?
sly*_*rel 41
特别是在发布时,我发现以下内容对于UI始终是准确的,无论UIDevice所说的方向是什么.
[UIApplication sharedApplication].statusBarOrientation
Run Code Online (Sandbox Code Playgroud)
        小智 10
self.interfaceOrientation在某些情况下是不可靠的.例如,在tabbar应用程序中重新排列选项卡会返回不正确的值.
但[UIApplication sharedApplication].statusBarOrientation总是可靠的.你为我节省了很多时间.谢谢.
|   归档时间:  |  
           
  |  
        
|   查看次数:  |  
           51274 次  |  
        
|   最近记录:  |