Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>My situation is:</strong></p> <ul> <li>UITabBarController has 2 items: 2 Navigation controller</li> <li>UINavigationController1 withRootView: ViewController1 </li> <li>UINavigationController2 withRootView: ViewController2.</li> <li>Now i want ViewController1 set shouldAutorotate:NO/maskPortrait and ViewController2 set shouldAutorotate/MaskAll.</li> </ul> <p><strong>So my implement:</strong> Create UITabBarController category and UINavigationCntroller category like</p> <p><strong>UITabBarController+autoRotate.h</strong></p> <pre><code>@interface UITabBarController (autoRotate) -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end </code></pre> <p><strong>UITabBarController+autoRotate.m</strong></p> <pre><code>#import "UITabBarController+autoRotate.h" @implementation UITabBarController (autoRotate) - (BOOL)shouldAutorotate { return [self.selectedViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.selectedViewController supportedInterfaceOrientations]; } @end </code></pre> <p><strong>UINavigationController+autoRotate.h</strong></p> <pre><code>@interface UINavigationController (autoRotate) -(BOOL)shouldAutorotate; - (NSUInteger)supportedInterfaceOrientations; @end </code></pre> <p><strong>UINavigationController+autoRotate.m</strong></p> <pre><code>@implementation UINavigationController (autoRotate) - (BOOL)shouldAutorotate { return [self.visibleViewController shouldAutorotate]; } - (NSUInteger)supportedInterfaceOrientations { return [self.visibleViewController supportedInterfaceOrientations]; } @end </code></pre> <p><strong>UIViewController1.m</strong></p> <pre><code>- (BOOL)shouldAutorotate { return NO; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskPortrait;; } </code></pre> <p><strong>UIViewController2.m</strong></p> <pre><code>- (BOOL)shouldAutorotate { return YES; } - (NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAll; } </code></pre> <p>It worked like a charm!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload