在我的应用程序中,我有一个带5个按钮的标签栏。总的应用程序只有肖像方向,我已正确设置。iOS应用程序 - 更改标签栏中的方向
我的问题是,当我点击标签栏的第二个按钮时,视图通常以纵向显示,但是当用户倾斜设备时,我希望将该特定视图更改为横向。是否可以将标签栏位置更改为横向,以及何时将其他按钮全部单击更改为纵向?
否则,当它倾斜我必须在没有tabbar的景观中单独显示视图,我该怎么做?
在我的应用程序中,我有一个带5个按钮的标签栏。总的应用程序只有肖像方向,我已正确设置。iOS应用程序 - 更改标签栏中的方向
我的问题是,当我点击标签栏的第二个按钮时,视图通常以纵向显示,但是当用户倾斜设备时,我希望将该特定视图更改为横向。是否可以将标签栏位置更改为横向,以及何时将其他按钮全部单击更改为纵向?
否则,当它倾斜我必须在没有tabbar的景观中单独显示视图,我该怎么做?
因此,很明显,您希望整个应用程序和纵向的所有视图除了第二个选项卡栏按钮触发的视图外,您希望始终出现在横向?
,如果我不糊涂你的问题,不是仅仅把下面的代码行中的视图数控制器的“viewDidLoad中”方法2
self.view.transform = CGAffineTransformMakeRotation(M_PI/2);
你可能想硬着头皮让您的项目在最高级别接受多个方向,然后根据UIViewController决定支持哪些方向。这将允许框架为你处理很多工作(总是一个好主意)。
在每个视图的控制器,重写这个方法:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
你将要返回YES
为您希望以支持任何方向。
为interfaceOrientation参数四个选项是:
UIInterfaceOrientationPortrait
UIInterfaceOrientationPortraitUpsideDown
UIInterfaceOrientationLandscapeLeft
UIInterfaceOrientationLandscapeRight
所以对于你的情况,你将要托管视图和标签栏,支持所有方向的视图控制器。这是函数是什么样子:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return YES;
}
但对于一个额外的细节,如果你想只支持横向左和纵向颠倒方向,功能应该是这样的:
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations.
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
一如果所有选项卡的ViewControllers在shouldAutorotateToInterfaceOrientation处返回YES,UITabBar仅支持旋转。
你可以达到你想要的东西,如果你让你的“肖像”选项卡检查它们是否可见(通过
tabbar.selectedViewController
或 tabbar.selectedIndex
与回复是,当他们未选中
虽然用户体验可能会令人困惑,但当用户在横向模式下更改标签时 提供了纵向视图...
试试这个w.r.t.:tabbar.selectedViewController
[[UIDevice currentDevice] setOrientation:UIDeviceOrientationLandscapeRight];