Autorotate ignored when changing tabs

帅比萌擦擦* 提交于 2019-12-03 21:51:29

I was having the same issue as you on one of my apps, with the difference that I was not using navigation controllers in the tab items.

I ended up creating a category for the UITabBarController (since it's not meant to be subclassed) for the method shouldAutorotate...

@implementation UITabBarController (orientation)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
#if DEBUG 
    NSLog(@"UITabBarController (orientation) -> shouldAutorotateToInterfaceOrientation: [%d]",toInterfaceOrientation);
#endif  
    //if(toInterfaceOrientation == UIInterfaceOrientationPortrait) return YES;
//  else return [self.selectedViewController shouldAutorotateToInterfaceOrientation:toInterfaceOrientation];
    if (self.selectedViewController == [self.viewControllers objectAtIndex:kLibraryStoreTabIndex])
        return NO;


    if( self.selectedViewController == [self.viewControllers objectAtIndex:kContactTabIndex]){

        return YES;
    }
// rest of the conditions depending of the tab 

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