加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

iOS 6:将视图控制器推入导航控制器堆栈时如何强制更改方向

发布时间:2020-12-15 01:50:11 所属栏目:百科 来源:网络整理
导读:参见英文答案 In iOS6,trouble forcing ViewController to certain interfaceOrientation when pushed on stack????????????????????????????????????3个 我认为这个问题到现在应该被问过一百万次,但我仍然无法找到答案. 这是我的层次结构:UINavigationCont
参见英文答案 > In iOS6,trouble forcing ViewController to certain interfaceOrientation when pushed on stack????????????????????????????????????3个
我认为这个问题到现在应该被问过一百万次,但我仍然无法找到答案.

这是我的层次结构:UINavigationController – > UIViewController 1 – >(推) – > UIViewController 2

UINavigationController:支持所有可能的方向
UIViewController 1:仅支持肖像
UIViewController 2:仅支持横向

如何仅将UIViewController 1锁定为纵向,同时仅将UIViewController 2锁定为横向?它甚至可能吗?到目前为止,我看到的是UIViewController 2始终采用UIViewController 1的方向.

请注意,这仅适用于iOS 6.

谢谢!

解决方法

我也发现了同样的问题.我发现每次都应该调用不应该调用函数,所以我改变了方向程序

先导入这个

#import <objc/message.h>

然后

-(void)viewDidAppear:(BOOL)animated
{

     if(UIDeviceOrientationIsPortrait(self.interfaceOrientation)){
        if ([[UIDevice currentDevice] respondsToSelector:@selector(setOrientation:)])
        {
            objc_msgSend([UIDevice currentDevice],@selector(setOrientation:),UIInterfaceOrientationLandscapeLeft );


        }
    }

}

希望这能帮助你.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读