如何将特定视图的方向更改为横向?
问题描述:
我在我的应用程序中有一个视图。我想在横向显示中显示的特定视图。 当用户进入该视图时,我想强制用户更改设备方向。当用户转到其他视图时,必须重置ti。我该怎么做?如何将特定视图的方向更改为横向?
答
我得到了答案
[UIApplication的sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight]。
float angle = M_PI/2; //rotate 180°, or 1 π radians
self.view.layer.transform = CATransform3DMakeRotation(angle, 0, 0.0, 1.0);
答
在它的视图控制器实现了两个消息:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight);
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
而这一切。
它仅适用于单个视图吗?这种观点有多少次? –
@VenkatManohar只有一次。意思是当用户点击一个按钮时,viewController将被加载,所以当它被加载时,我想改变方向。 – user1244311
[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];您希望将哪个方向放在那里......它的工作原理 –