Autorotation, UIWebView and UITabBarController

痴心易碎 提交于 2019-12-06 13:58:41

Consider a different approach: rather than presenting your UIWebView with the movie in it as yet an UIViewController in your whole tab controller heirarchy, which ties you into the whole rotation problem, try replacing your top level view controller (UITabBarController) with a totally different UIViewController (containing the UIWebView).

When you want to exit the fullscreen movie mode, reinstate the UITabBarController as the top level view controller again. N.B. do not forget to remove the 'old' view controller when you do a switch -- UIWindow gets very unhappy when it has multiple child views, and autorotation messages don't get sent, etc.

I've seen apps use strategies like this when faced with such autorotation hurdles.

This strategy might seem a bit 'unglued', and you might have to do a little fiddling around the finer aspects of the switching, but it's worth a look.

You can send a notification in viewcontrollers to say other view controllers that rotation is required so that they return YES to all orientations.When you leave the view controllers you send another notifications that it is no longer required.With that approach you could have autorotation only in the views that you want and as soon as you leave these views you deactivate it.

In my app i am using this approach in a web view where auto rotation is required but not in other view controllers.

  • (void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    NSNotification *autoRotationNotification = [NSNotification notificationWithName:kShouldAutoRotateNotification object:[NSNumber numberWithBool:YES]]; [[NSNotificationCenter defaultCenter] postNotification:autoRotationNotification];

}

  • (void)viewWillDisappear:(BOOL)animated{ [super viewWillDisappear:animated];

    NSNotification *autoRotationNotification = [NSNotification notificationWithName:kShouldAutoRotateNotification object:[NSNumber numberWithBool:NO]]; [[NSNotificationCenter defaultCenter] postNotification:autoRotationNotification]; }

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