您的位置:首页 > 移动开发 > IOS开发

iOS在某特定界面强制横屏

2016-04-13 00:00 489 查看
摘要: 项目是不支持横屏的,但在某个界面需要横屏

1、先上代码:

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

再次运行,完全旋转!

PS: 此种方法只针对present过来的界面有效,而对于push过来的是无效的。

2、获取设备的屏幕方向:

if (![UIDevice currentDevice].generatesDeviceOrientationNotifications) {
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
}
NSLog(@"%d",[UIDevice currentDevice].orientation);

[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息