开发者

iPad tab bar app not autorotating

开发者 https://www.devze.com 2023-01-12 04:15 出处:网络
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 co

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

0

精彩评论

暂无评论...
验证码 换一张
取 消