iOS 技术分享

iOS - 横屏竖屏切换

2020-08-06  本文已影响0人  Joh蜗牛

引入:

// 横屏设置
#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];
上一篇 下一篇

猜你喜欢

热点阅读