iOS 某一个界面实现强制横屏

本文介绍了一种在iOS应用中使UIViewController强制横屏显示的方法。通过编写Objective-C代码实现了一个名为orientationToPortrait的方法,该方法接受一个UIInterfaceOrientation类型的参数来控制设备的方向。使用此方法可以在特定的ViewController中轻松地实现横屏功能。

需求:
让push的ViewController界面强制横屏

一、配置
这里写图片描述

二、添加强制横屏方法

#pragma mark -- 强制转换横屏
- (void)orientationToPortrait:(UIInterfaceOrientation)orientation {

    SEL selector = NSSelectorFromString(@"setOrientation:");
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[UIDevice instanceMethodSignatureForSelector:selector]];
    [invocation setSelector:selector];
    [invocation setTarget:[UIDevice currentDevice]];
    int val = orientation;
    [invocation setArgument:&val atIndex:2];//前两个参数已被target和selector占用
    [invocation invoke];
}

三、在需要跳转的方法中调用上述方法,令其转换屏幕

    [self orientationToPortrait:UIInterfaceOrientationLandscapeLeft];

四、返回竖屏的方法中调用

    [self orientationToPortrait:UIInterfaceOrientationPortrait];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值