UITabBarController + autorotation

倾然丶 夕夏残阳落幕 提交于 2019-12-12 10:27:33

问题


I created an application with a TabBarController using IB who have 4 TabBarItems and so display 4 differents ViewControllers. To allow a landscape orientation I must add this code in all of my ViewController:


- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
     return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown ? NO : YES);
}

The problem is I don't want for example the secondViewController to autorotate, How can I do that? Because everytime I delete the code above in one of my ViewController, every ViewControllers not rotate anymore.

Thanks


回答1:


Leave the code in there, but you'll want to do one of two things:

  1. Disable the non-rotatable tab when showing landscape view OR
  2. In the viewWillAppear or viewDidAppear for that tab, force rotation to portrait.

eg:

[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES]


来源:https://stackoverflow.com/questions/2442385/uitabbarcontroller-autorotation

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