iOS8 Rotation issue with UITabBarController and UINavigation Controller

这一生的挚爱 提交于 2019-12-10 04:34:09

问题


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.


回答1:


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");
}


来源:https://stackoverflow.com/questions/26354825/ios8-rotation-issue-with-uitabbarcontroller-and-uinavigation-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!