iPad tab bar app not autorotating
I made a tab bar application, but it will not rotate into landscape.
I have the 'shouldAutoRotate' set to "return YES" but that doesn't work... Any sugg开发者_开发技巧estions?
All of the view controllers in the tab bar controller need to return YES for landscape in order for it to rotate.
I also think so because when app launches all the view controller's 'shouldAutoRotate' getting fired..
What happened in my app I was using off the shelf UITabBarController which I dragged over in xCode interface builder. It did not rotate itself (I guess by defauls it just displays portrait).
Solution was to create a new class (with right click on the file list) New File > Objective C Class > and then in "Subclass of:" type UITabBarController, and give it a meaningful name (like MyUITabBarControllerInHorisontalOrientation)
What happened you created a file which has all the functions of UITabBarController, but also you can add few more to it. So you need to add in .m file a function like this:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
Boolean ans = (UIInterfaceOrientationLandscapeLeft == interfaceOrientation);
//this will display tabbar as a landscape left,
// but you can add more orientations using && operator
return ans;
}
and then in interface builder (the wysiwyg interface where you drag and drop buttons) click your UITabBarController you dragged over and in Utilities > Identity Inspector > Custom class (often visible as a right hand side panel) chose your MyUITabBarControllerInHorisontalOrientation.
I hope it helps
精彩评论