2012-10-08 68 views
1

我在我的应用程序中有一个视图。我想在横向显示中显示的特定视图。 当用户进入该视图时,我想强制用户更改设备方向。当用户转到其他视图时,必须重置ti。我该怎么做?如何将特定视图的方向更改为横向?

+0

它仅适用于单个视图吗?这种观点有多少次? –

+0

@VenkatManohar只有一次。意思是当用户点击一个按钮时,viewController将被加载,所以当它被加载时,我想改变方向。 – user1244311

+0

[[UIApplication sharedApplication] setStatusBarOrientation:UIDeviceOrientationLandscapeLeft animated:NO];您希望将哪个方向放在那里......它的工作原理 –

回答

1

我得到了答案

[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); 
+0

它可能正常工作,但它不是正确的解决方案。 –

+0

@AndreyChevozerov:那么如何得到它? – user1244311

+0

请参阅下面的答案。 –

3

在它的视图控制器实现了两个消息:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{ 
    return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    return UIInterfaceOrientationMaskLandscape; 
} 

而这一切。

相关问题