iOS8 Rotation issue with UITabBarController and UI

2019-04-29 00:46发布

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条回答
相关推荐>>
2楼-- · 2019-04-29 01:30

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");
}
查看更多
登录 后发表回答