简体   繁体   中英

UIInterfaceOrientation in UINavigationViewController

I'm having issue with auto rotating in my view which is inside a UINavitionViewController and the navigationViewcontroller is inside a tabBarViewController.

I subclassed tabBarViewController. The problem is the interfaceorientation works fine on the first view inside the tabViewController, but whenever I push to another view it doesn't work.

This is a code in subclass tabBarController

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    return YES;
    if([self.selectedViewController isKindOfClass:[UINavigationController class]]){
        return [[(UINavigationController*)self.selectedViewController visibleViewController] shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    } else {
        return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    }
}

You have to override shouldAutorotateToInterfaceOrientation: in the view controllers for all the views in the tab bar.

If a view controller's shouldAutorotateToInterfaceOrientation: returns NO, then the tab bar will not rotate, even if the view is hidden at the time of the rotation.

You should have a UIViewController inside a UINavigationController inside a UITabBarController . The rotation is decided by shouldAutorotateToInterfaceOrientation: in your UIViewController . You need to override that method for every UIViewController to return the desired value, ie, YES if you want it to rotate and NO if you don't want it to.

You shouldn't override shouldAutorotateToInterfaceOrientation: in UINavigationController or UITabBarController .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM