iOS 怎样切换横竖屏


上一篇文章是写我实现横竖屏之后遇到的问题,这里说一下是怎么实现横竖屏的


首先,因为我做的是其他页面禁止横屏,只要一个页面横屏,那么第一步,需要在AppDelegate中设置只能竖屏 然后在指定界面开启横屏.


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    self.spOrientation = UIInterfaceOrientationMaskPortrait;

    return YES;

    

}

-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

    

    return self.spOrientation;

}


下面是指定页面开启横屏

-(void)viewWillAppear:(BOOL)animated{

    AppDelegate * delegate = [UIApplication sharedApplication].delegate;

    delegate.spOrientationUIInterfaceOrientationMaskAll;

}

-(void)viewWillDisappear:(BOOL)animated{

    AppDelegate * delegate = [UIApplication sharedApplication].delegate;

    delegate.spOrientationUIInterfaceOrientationMaskPortrait;

}


因为前一个页面要求禁止横屏 则需要在上一个页面写 


- (void)viewWillAppear:(BOOL)animated {


    [super viewWillAppear:animated];

    

    [[UIDevice currentDevice] setValue: [NSNumber numberWithInteger: UIInterfaceOrientationPortrait] forKey:@"orientation"];

}


这样就做到横竖屏切换啦

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值