【问题标题】:UITabbar orientation issueUITabbar 方向问题
【发布时间】:2011-05-14 07:29:56
【问题描述】:

我有一个包含两个选项卡的 tabBarController,我希望 1 个选项卡支持方向,但另一个不支持,怎么做?我已经尝试过代码:

@implementation UITabBarController (CustomTabbar)

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     if(self.tabBarController.selectedIndex==1){
    
    
    
        NSLog(@"rotate");
        return YES;
    

    } 别的 {

    NSLog(@"no rotate");
    return  NO;
    

    }

} @结束

但是在我将 view2 旋转到横向模式并返回到 view1 后,view1 也会变成横向,直到我将其旋转回 potrait,但我需要的是 view1 在出现时始终保持 potrait,可以帮忙吗?

问候,

sathish

【问题讨论】:

    标签: ios4 orientation uitabbar


    【解决方案1】:

    您不想旋转的视图控制器上,确保在:

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    

    你返回NO;

    您将它返回给 tabBar 控制器,而不是实际的 viewController。

    【讨论】:

      【解决方案2】:

      使用 UITabBar 控制器时,所有方向消息都会转到标签栏并停在那里。

      因此,要完成您想要做的事情,您必须创建一个继承自 UITabBarController 的新类并使用它。

      @interface CustomUITabBarController : UITabBarController
      

      之后,您有 2 个选项来控制控制器的方向,这两个选项您都必须使用 shouldAutorotateToInterfaceOrientation 选择器。

      您可以使用标签栏当前选定的索引来返回 YES 或 NO 的方向

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
      {
      
          if(self.selectedIndex == 0) {
              return NO;
          } else {
              return YES;
          }
      
      }
      

      或者你可以让控制器自己决定(就像你之前尝试做的那样)

      - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
      {
      
          if (self.selectedViewController) {
              return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
          } else {
              return YES;
          }
      }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-09-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多