Iphone 在运行时设置UIInterfaceOrientation
我在故事板上有5个视图。我希望每个视图方向都不同,例如一个视图将是Iphone 在运行时设置UIInterfaceOrientation,iphone,ipad,xcode4.3,Iphone,Ipad,Xcode4.3,我在故事板上有5个视图。我希望每个视图方向都不同,例如一个视图将是UIInterfaceOrientation和scapeRight另一个视图将是UIInterfaceOrientation和scapeLeft或UIInterfaceOrientation纵向或UIInterfaceOrientation纵向。那么如何将视图的方向设置为不同的呢 我用过 [[UIDevice currentDevice]设置方向:UIInterfaceOrientation和scapeRight] 但它显示警告“
UIInterfaceOrientation和scapeRight
另一个视图将是UIInterfaceOrientation和scapeLeft
或UIInterfaceOrientation纵向
或UIInterfaceOrientation纵向
。那么如何将视图的方向设置为不同的呢
我用过
[[UIDevice currentDevice]设置方向:UIInterfaceOrientation和scapeRight]代码>
但它显示警告“UIDevice可能不会响应setOrientation”。根据我使用的许多stackoverflow编写器
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
//return UIInterfaceOrientationLandscapeLeft;
return (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
这是上面的代码,但它在我的项目中不起作用。那么,屏幕方向的正确步骤是什么呢。
提前谢谢。试试这个
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft animated:YES];
无法设置UIDeviceOrientation
,因为它是物理参数。若你们把设备放在手上,那个么你们是如何通过编程将其设置为横向的呢<代码>UIDeviceOrientation
的意思是-设备方向,而不是接口。此答案描述了方向之间的差异:
您必须将-(BOOL)shouldAutorotateToInterfaceOrientation:
放入每个viewController,并检查方向是否正确。如果您按下仅支持(例如)上下移动的viewController,它将上下移动
注:
- 如果您在tabbar环境中,行为会有所不同。如果是这样,请询问李>
- 如果你说的是rootViewController,你的应用程序应该与第一个viewController(Info.plist)相对应
您可以使用
[UIViewController attemptRotationToDeviceOrientation]代码>尝试将所有视图控制器旋转到设备当前方向。不能强制设置旋转 那么,有没有办法以编程方式将我的设备保持在纵向模式?要保持从shouldAutorotateToInterfaceOrientation返回,纵向方向为YES。