iOS开发

iOS 只支持横屏/竖屏

2017-06-30  本文已影响435人  柴小斌

写在前面

今天在写一个可以制定计划的小应用,我希望在iPhone上只支持横屏,百度搜了一下,杂七杂八的,还是自己研究一下比较靠谱,直接放代码:

#pragma mark -只支持横屏
- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window
{
return isPhone() ? UIInterfaceOrientationMaskLandscape : UIInterfaceOrientationMaskAll;
}
BOOL isPhone(void)
{
return UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
}

将上面两段代码直接粘贴到APPDelegate.m中就行了
要想只支持竖屏,就把UIInterfaceOrientationMaskLandscape换成UIInterfaceOrientationMaskPortrait.这是一个枚举类型,里面还有好多值,什么倒立竖屏,左横屏,右横屏之类的,你们感兴趣可以自己去试试.

上一篇下一篇

猜你喜欢

热点阅读