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

objective-c – didRotateFromInterfaceOrientation:没有为在iO

发布时间:2020-12-16 06:58:31 所属栏目:百科 来源:网络整理
导读:有一个视图控制器(让我们将其命名为parent),它使用presentModalViewController:animated:来呈现其他视图控制器(让我们将其命名为模态),然后旋转设备.两个控制器都支持所有方向.这里发生了什么: 旋转后,模态控制器接收didRotateFromInterfaceOrientation:
有一个视图控制器(让我们将其命名为parent),它使用presentModalViewController:animated:来呈现其他视图控制器(让我们将其命名为模态),然后旋转设备.两个控制器都支持所有方向.这里发生了什么:

>旋转后,模态控制器接收didRotateFromInterfaceOrientation:
>在解除模态控制器之前,父控制器也接收didRotateFromInterfaceOrientation:但是,仅当基本SDK设置为4.3(或更低)时才会发生.如果将基本SDK设置为5,则父控制器不会收到此消息.在4.3中,我根据didRotateFromInterfaceOrientation:中的新方向更新了父接口,并且在隐藏模态控制器后显示正确,但是在iOS 5中,它没有被调用,并且在隐藏模态控制器后父接口被搞砸了.

那么,如果在模态控制器可见时旋转设备,我该怎么做才能正确地将父控制器的界面更新为新的方向?

解决方法

我遇到过类似的问题.我的解决方案是将我的方向处理代码移动到一个单独的方法中,并从旋转方法和viewWillAppear调用:

//.h
@interface SomeViewController

- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation;

@end


//.m
@implementation SomeViewController


- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];

    UIInterfaceOrientation currentOrientation = [[UIApplication sharedApplication] statusBarOrientation];
    [self layoutForInterfaceOrientation:currentOrientation];
}

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toOrientation duration:(NSTimeInterval)duration {

    [self layoutForInterfaceOrientation:toOrientation];
}

- (void)layoutForInterfaceOrientation:(UIInterfaceOrientation)orientation {

    // layout views
}

@end

(编辑:李大同)

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

    推荐文章
      热点阅读