简体   繁体   English

在iOS 8中的呈现视图控制器中,界面方向不正确

[英]interface orientation not correct in presented view controllers in iOS 8

in iOS 7 and earlier, I was able to make UI changes in viewDidLayoutSubviews like so: 在iOS 7及更早版本中,我能够在viewDidLayoutSubviews进行UI更改,如下所示:

- (void)viewDidLayoutSubviews {

    [super viewDidLayoutSubviews];

    if ( UIInterfaceOrientationIsLandscape(self.interfaceOrientation) ) {

        //update views for landscape

    }

    else {

        //update views for portrait

    }

}

I can still do this in iOS 8 except in view controllers that are presented by other view controllers. 我仍然可以在iOS 8中执行此操作, 在其他视图控制器提供的视图控制器中除外 When a view controller is presented by another view controller, this does not work, because the self.interfaceOrientation property is not correct in the presented view controller. 当视图控制器由另一个视图控制器呈现时,这不起作用,因为在所呈现的视图控制器中self.interfaceOrientation属性不正确。 It does not reflect the current orientation, but rather the orientation right before the device rotation. 它不反映当前方向,而是反映设备旋转之前的方向。

The issue is not present if presenting a view controller on iPad with modalPresentationStyle set to UIModalPresentationPageSheet . 如果在iPad上呈现视图控制器并且modalPresentationStyle设置为UIModalPresentationPageSheet ,则该问题不存在。 In other words, the issue is only present when presenting a full screen view controller. 换句话说,只有在呈现全屏视图控制器时才会出现此问题。

Any suggestions? 有什么建议?

Try using this instead: 请尝试使用此代码:

[[UIApplication sharedApplication] statusBarOrientation]

Also, if you are dropping support for iOS 7 and going 8-only, I recommend you drop interface orientation handling in favor of trait collections and size classes, if you can. 此外,如果您放弃对iOS 7的支持并且只支持8-only,我建议您删除界面方向处理,以支持特征集合和大小类,如果可以的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM