UITabbar方向问题

发布于 2024-10-03 21:20:02 字数 585 浏览 3 评论 0原文

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

@implementation UITabBarController (CustomTabbar)

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

     if(self.tabBarController.selectedIndex==1){
    
    
    
     NSLog(@"旋转");
        返回是;
    

    } 别的 {

    NSLog(@"不旋转");
    返回否;
    

    }

} @end

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

问候,

萨蒂什

I have a tabBarController which contain two tab, i would like 1 tab is support orientation but another one not,how to do that? i have tried the code:

@implementation UITabBarController (CustomTabbar)

  • (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {

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

    }
    else
    {

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

    }

}
@end

but after i rotating the view2 to landscape mode and back to view1, view1 become landscape as well until i rotate it back to potrait,but the thing i need is view1 always remain potrait when it appear,can help?

Regards,

sathish

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

昔梦 2024-10-10 21:20:02

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

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

您返回NO;

您正在为 tabBar 控制器返回它,而不是实际的 viewController。

On the view controller that you dont want rotating, make sure that on the:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

You return NO;

You are returning it for the tabBar controller, not the actual viewController.

指尖上的星空 2024-10-10 21:20:02

使用 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;
    }
}

When using a UITabBar controller, all orientation messages goes to the tab bar and stop there.

So, to accomplish what you are trying to do, you have to create a new class inherited from UITabBarController and use that instead.

@interface CustomUITabBarController : UITabBarController

After that you have 2 options to control the orientation of your controllers and both of them you will have touse the shouldAutorotateToInterfaceOrientation selector.

You can either use the tab bar current selected index to return YES or NO for the orientation

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if(self.selectedIndex == 0) {
        return NO;
    } else {
        return YES;
    }

}

OR you could let the controller decide for itself (as you were trying to do before)

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{

    if (self.selectedViewController) {
        return [self.selectedViewController shouldAutorotateToInterfaceOrientation:interfaceOrientation];
    } else {
        return YES;
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文