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

objective-c – iOS 6 UIInterfacePortrait ONLY视图控制器被呈

发布时间:2020-12-14 19:07:06 所属栏目:百科 来源:网络整理
导读:就像许多其他人一样,我遇到的问题是只有一个或两个viewcontrollers支持纵向和横向界面方向,在另一个肖像应用程序中.在iOS 6之前一切正常,但突然自动停止工作.感谢这里的一些很好的问题,我能够通过让初始的navController通过以下方式返回个人topViewControlle
就像许多其他人一样,我遇到的问题是只有一个或两个viewcontrollers支持纵向和横向界面方向,在另一个肖像应用程序中.在iOS 6之前一切正常,但突然自动停止工作.感谢这里的一些很好的问题,我能够通过让初始的navController通过以下方式返回个人topViewController对shouldAutorotate的首选项来解决这个问题:

- (BOOL)shouldAutorotate
{
    return  self.topViewController.shouldAutorotate;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

但是,我偶然发现了一个新问题.根vc(viewController A)不应该自动旋转,只应支持肖像.导航堆栈中的ViewController B支持纵向和横向.如果我在viewController B中,并且处于横向状态,并触摸“返回”以将视图弹回到viewController A … vc A加载在横向中,它不应该支持,并且不会旋转回肖像,因为shouldAutorotate for vc A设置为NO …

任何关于如何处理这个问题的想法将不胜感激.我最初的想法是使用手动方法覆盖vc B的“后退”按钮,如果视图处于横向状态,则首先强制旋转回纵向…然后将视图控制器弹回到vc A ……但我无法弄清楚如何以编程方式强制旋转.有任何想法吗?

这是vc A中的接口方法:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return NO;
}

-(BOOL)shouldAutorotate
{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

这是他们在vc B中的内容:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

-(BOOL)shouldAutorotate
{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
    return UIInterfaceOrientationPortrait;
}

解决方法

在vcA集中

-(BOOL)shouldAutorotate
{
  return YES;
}

但保持

-(NSUInteger)supportedInterfaceOrientations
{
  return UIInterfaceOrientationPortrait;
}

然后,当您从vcB返回时,视图将旋转回(仅)支持的方向

(编辑:李大同)

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

    推荐文章
      热点阅读