<i id='zixYM'><tr id='zixYM'><dt id='zixYM'><q id='zixYM'><span id='zixYM'><b id='zixYM'><form id='zixYM'><ins id='zixYM'></ins><ul id='zixYM'></ul><sub id='zixYM'></sub></form><legend id='zixYM'></legend><bdo id='zixYM'><pre id='zixYM'><center id='zixYM'></center></pre></bdo></b><th id='zixYM'></th></span></q></dt></tr></i><div id='zixYM'><tfoot id='zixYM'></tfoot><dl id='zixYM'><fieldset id='zixYM'></fieldset></dl></div>

      <small id='zixYM'></small><noframes id='zixYM'>

    1. <tfoot id='zixYM'></tfoot>

    2. <legend id='zixYM'><style id='zixYM'><dir id='zixYM'><q id='zixYM'></q></dir></style></legend>
      • <bdo id='zixYM'></bdo><ul id='zixYM'></ul>

      UINavigationController 中的 ViewController 方向更改

      时间:2023-06-13
      <tfoot id='4nvDP'></tfoot>

        <i id='4nvDP'><tr id='4nvDP'><dt id='4nvDP'><q id='4nvDP'><span id='4nvDP'><b id='4nvDP'><form id='4nvDP'><ins id='4nvDP'></ins><ul id='4nvDP'></ul><sub id='4nvDP'></sub></form><legend id='4nvDP'></legend><bdo id='4nvDP'><pre id='4nvDP'><center id='4nvDP'></center></pre></bdo></b><th id='4nvDP'></th></span></q></dt></tr></i><div id='4nvDP'><tfoot id='4nvDP'></tfoot><dl id='4nvDP'><fieldset id='4nvDP'></fieldset></dl></div>

          <small id='4nvDP'></small><noframes id='4nvDP'>

            <bdo id='4nvDP'></bdo><ul id='4nvDP'></ul>
                <tbody id='4nvDP'></tbody>

                <legend id='4nvDP'><style id='4nvDP'><dir id='4nvDP'><q id='4nvDP'></q></dir></style></legend>
                本文介绍了UINavigationController 中的 ViewController 方向更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                所以我有以下层次结构:

                So I have the following hierarchy:

                UINavigationController --> RootViewController (UIViewController) --> UITableViewController --> DetailViewController (UIViewController)

                UINavigationController --> RootViewController (UIViewController) --> UITableViewController --> DetailViewController (UIViewController)

                我想将 RootViewController 上的方向锁定为仅纵向,但保留其余视图控制器的所有方向.

                I want to lock the orientation on RootViewController to Portrait only, but leave all orientations for the rest view controllers.

                如果我把它放到子类 UINavigationController:

                If I put this to subclassed UINavigationController:

                - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
                {
                    // Return YES for supported orientations
                    return (interfaceOrientation == UIInterfaceOrientationPortrait);
                }
                
                -(NSUInteger)supportedInterfaceOrientations{
                    return UIInterfaceOrientationMaskPortrait;
                }
                

                然后所有视图控制器都被锁定为纵向.

                All view controllers are then locked to portrait.

                我的问题是,有没有办法只将 RootViewController 锁定为 Portrait,而将所有选项留给其他视图控制器?

                My question is, is there a way to lock only RootViewController to Portrait, but leave all options for other view controllers?

                推荐答案

                查看此处的链接以修复 iOS 6 中的自动旋转并根据视图设置方向支持:http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/

                check the link here for fixing autorotation in iOS 6 and set orientation support per view basis: http://www.disalvotech.com/blog/app-development/iphone/ios-6-rotation-solution/

                你可以这样做:

                1. 在您的 .m 文件中创建一个自定义导航控制器,它是 UINavigationController 的子类:

                 - (BOOL)shouldAutorotate
                 {
                      return self.topViewController.shouldAutorotate;
                 }
                 - (NSUInteger)supportedInterfaceOrientations
                 {
                      return self.topViewController.supportedInterfaceOrientations;
                 }
                

              1. 在你的 AppDelegate.h,

                  @interface AppDelegate : UIResponder <UIApplicationDelegate> {
                
                      UINavigationController *navigationController;
                      ViewController *viewController;
                  }
                
                  @property (strong, nonatomic) UIWindow *window;
                  @property (strong, nonatomic) ViewController *viewController;
                

                AppDelegate.m中,

                  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
                  {
                        // set initial view
                       self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
                
                       viewController = [[ViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
                
                       navigationController = [[CustomNavigationController alloc]
                                    initWithRootViewController:viewController]; // iOS 6 autorotation fix
                       [navigationController setNavigationBarHidden:YES animated:NO];
                
                        self.window = [[UIWindow alloc]
                           initWithFrame:[[UIScreen mainScreen] bounds]];
                
                        [self.window setRootViewController:navigationController]; // iOS 6 autorotation fix
                        //[self.window addSubview:navigationController.view];
                
                        [self.window makeKeyAndVisible];
                
                
                         return YES;
                  }
                
                
                  - (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window  // iOS 6 autorotation fix
                  {
                          return UIInterfaceOrientationMaskAll;
                
                  }
                

              2. 在您的 rootViewController 中,无论事件推送第二个视图控制器,请执行以下操作:

              3. in your rootViewController, for whatever the event push the second view controller, do this:

                  - (IBAction)pushSecondViewController:(id)sender {
                
                    // push second view controller
                    SecondViewController *secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
                    [self.navigationController pushViewController:secondViewController animated:YES];
                   }
                

              4. 在每个视图控制器中,添加

              5. in your each view controller, add

                   - (BOOL)shouldAutorotate{}
                   - (NSUInteger)supportedInterfaceOrientations{}
                

                对于 iOS 6,您可以单独设置每个视图控制器所需的方向支持.

                for iOS 6, you can set each view controller whatever the orientation support you want individually.

                对于iOS 5及以下,可以设置

                for iOS 5 and below, you can set

                   - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{}
                

              6. 所有功劳归于在链接中编写示例应用的 John DiSalvo.

                All the credits goes to John DiSalvo who wrote the sample app in the link.

                希望这会有所帮助.

                这篇关于UINavigationController 中的 ViewController 方向更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:UINavigationController 中的自定义后退按钮 下一篇:UISplitViewController 内的 UITabBarController 内的 UINavigationC

                相关文章

                <tfoot id='A4tf2'></tfoot>
                <legend id='A4tf2'><style id='A4tf2'><dir id='A4tf2'><q id='A4tf2'></q></dir></style></legend>
                  • <bdo id='A4tf2'></bdo><ul id='A4tf2'></ul>

                  <small id='A4tf2'></small><noframes id='A4tf2'>

                    <i id='A4tf2'><tr id='A4tf2'><dt id='A4tf2'><q id='A4tf2'><span id='A4tf2'><b id='A4tf2'><form id='A4tf2'><ins id='A4tf2'></ins><ul id='A4tf2'></ul><sub id='A4tf2'></sub></form><legend id='A4tf2'></legend><bdo id='A4tf2'><pre id='A4tf2'><center id='A4tf2'></center></pre></bdo></b><th id='A4tf2'></th></span></q></dt></tr></i><div id='A4tf2'><tfoot id='A4tf2'></tfoot><dl id='A4tf2'><fieldset id='A4tf2'></fieldset></dl></div>