iOS在某特定界面強制橫屏

一、先上代碼:code

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskAll;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
    return NO;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationLandscapeRight;
}

再次運行,徹底旋轉!io

PS: 此種方法只針對present過來的界面有效,而對於push過來的是無效的。class

二、獲取設備的屏幕方向:方法

if (![UIDevice currentDevice].generatesDeviceOrientationNotifications) {
        [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    }
    NSLog(@"%d",[UIDevice currentDevice].orientation);
    
    [[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
相關文章
相關標籤/搜索