UITabBarController和UINavigation Controller的iOS8旋转问题 [英] iOS8 Rotation issue with UITabBarController and UINavigation Controller

查看:239
本文介绍了UITabBarController和UINavigation Controller的iOS8旋转问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对iOS8有一个问题。



这里我有视图层次结构。



窗口==> UITabBarController ==> 2 Tab
Tab 1 ==> UINavigationController1 ==> UIViewController1作为根视图控制器
Tab 2 ==> UINavigationController2 ==> UIViewController2作为根视图控制器



现在一切都是完美的,只有一个方向。



但问题在于这个测试步骤:


  1. 将日志放入ViewController的viewDidLoad方法中以跟踪事件

  2. 启动应用程序

  3. FirstViewController的viewDidLoad将呼叫。现在只留在这个视图上。

  4. 旋转到横向。

  5. 这是神奇的部分。 SecordViewController的viewDidLoad方法被调用但尚未被Tab2激活,然后它也加载了viewDidLoad。

此问题仅适用于iOS8。

为所有设备测试过。

解决方案

我遇到了同样的问题。我注意到在iOS8上,当设备的方向改变时,
viewWillTransitionToSize:withTransitionCoordinator:在UITabBarController上调用,而UITabBarController调用尚未加载的任何视图控制器的viewDidLoad方法。 / p>

现在,在我的UITabBarController子类中,我重写此方法以不调用[super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]。

   - (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id< UIViewControllerTransitionCoordinator>)coordinator 
{
//不要调用[super viewWillTransitionToSize:size withTransitionCoordinator:协调器];
NSLog(@设备orinetation已更改);
}


I have one issue with iOS8.

Here I have structure of my view hierarchy.

Window ==> UITabBarController ==> 2 Tab Tab 1 ==> UINavigationController1 ==> UIViewController1 as root view controller Tab 2 ==> UINavigationController2 ==> UIViewController2 as root view controller

Now everything works perfect with one orientation.

But problem is with this testing steps:

  1. Put log in both ViewController's viewDidLoad method for tracking event
  2. Start app
  3. FirstViewController's viewDidLoad will call. Now stay on this view only.
  4. Rotate to landscape.
  5. This is magic part. SecordViewController's viewDidLoad method get called which is not yet activated by Tab2 then also it is loading with viewDidLoad.

This issue is only on iOS8.
Tested for all devices.

解决方案

I had the same problem. I noticed that on iOS8 when the orientation of the device is changing viewWillTransitionToSize:withTransitionCoordinator: is getting called on UITabBarController, and UITabBarController calls viewDidLoad method of any viewcontroller that has not been loaded yet.

For now,in my UITabBarController subclass I override this method to not call [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator].

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator
{
    //Do not call [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
    NSLog(@"Device orinetation changed");
}

这篇关于UITabBarController和UINavigation Controller的iOS8旋转问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆