UITabBarController, MoreNavigationController and the Holy Grail of Device Rotation

后端 未结 3 644
春和景丽
春和景丽 2020-12-28 11:03

UPDATE: See my answer to this question first. This appears to be a bug. A minimal test case has been created and a report has been filed with Apple. (Fixed as of iPh

3条回答
  •  渐次进展
    2020-12-28 11:19

    Apple advises against subclassing UITabBarController, so I found an easy way to handle autorotation using categories instead. It doesn't fix your bug with the More... view controllers, but I think it's a more Apple-friendly way of getting the job done (and means less subclassing for you).

    To make every tab in my application autorotate properly, I've defined -shouldAutorotateToInterfaceOrientation: in my custom view controllers, but they are all inside UINavigationControllers within a UITabBarController, so the message won't get sent down the chain to my VC until those two also respond. So I added the following lines to my app delegate files:

    Added to the bottom of MyAppDelegate.h

    @interface UITabBarController (MyApp)
    @end
    
    @interface UINavigationController (MyApp)
    @end
    

    Added to the bottom of MyAppDelegate.m

    @implementation UITabBarController (MyApp) 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return YES;
    }
    @end
    
    @implementation UINavigationController (MyApp) 
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
        return YES;
    }
    @end
    

提交回复
热议问题