UITabbar方向问题
我有一个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您不想旋转的视图控制器上,请确保:
您返回NO;
您正在为 tabBar 控制器返回它,而不是实际的 viewController。
On the view controller that you dont want rotating, make sure that on the:
You return NO;
You are returning it for the tabBar controller, not the actual viewController.
使用 UITabBar 控制器时,所有方向消息都会发送到选项卡栏并停在那里。
因此,为了完成您想要做的事情,您必须创建一个从 UITabBarController 继承的新类并使用它。
之后,您有 2 个选项来控制控制器的方向,并且您都必须使用 shouldAutorotateToInterfaceOrientation 选择器。
您可以使用选项卡栏当前选定的索引来返回 YES 或 NO 的方向,
或者您可以让控制器自行决定(就像您之前尝试做的那样)
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.
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
OR you could let the controller decide for itself (as you were trying to do before)