美文网首页iOS 技术分享
iOS - 横屏竖屏切换

iOS - 横屏竖屏切换

作者: Joh蜗牛 | 来源:发表于2020-08-06 15:42 被阅读0次

引入:

// 横屏设置
#import "AppDelegate.h"
#import "UIDevice+TFDevice.h"

切换为横屏

AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    //允许转成横屏
    appDelegate.allowRotation = YES;
    //调用横屏代码
    [UIDevice switchNewOrientation:UIInterfaceOrientationLandscapeRight];

切换回竖屏

AppDelegate * appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
    appDelegate.allowRotation = NO;//关闭横屏仅允许竖屏
    //切换到竖屏
    [UIDevice switchNewOrientation:UIInterfaceOrientationPortrait];

相关文章

网友评论

    本文标题:iOS - 横屏竖屏切换

    本文链接:https://www.haomeiwen.com/subject/tizzrktx.html