如何locking在iPhone纵向/横向屏幕?

我的应用程序支持所有的方向,但在less数情况下,我想locking屏幕

纵向/横向模式。

在我的应用程序中,我有两种pdf文档。

一个是纵向文件,另一个是横向文件。

我只想在纵向视图中打开纵向文档,而在纵向文档中打开

仅景观视图。

我想这样做:如果我的应用程序打开横向视图,我点击

纵向文档,所以它必须旋转纵向视图和相同的景观如此

我的应用程序打开纵向视图,当我点击景观文件

必须旋转或者只能在横向打开文档。

希望我让你们明确的赦免我的英语希望你明白我想要什么

需要你的帮助 。

先谢谢你

这里是我的一些代码:

- (void)viewDidLoad { [super viewDidLoad]; UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) { NSLog(@"Portrait"); if ([orientationObject isEqualToString:@"p"]) { //If the document is portrait pdfScrollViewFrame = CGRectMake(-0.0, -80.0, 770.0, 1085.0); } else{ // If the document is landscape pdfScrollViewFrame = CGRectMake(-0.0, -40.0, 770.0, 1130.0); } } else{ NSLog(@"Landscape"); if ([orientationObject isEqualToString:@"p"]) { //If the document is portrait pdfScrollViewFrame = CGRectMake(65.0, -80.0, 620.0, 1110.0); } else{ //if the document is landscape pdfScrollViewFrame = CGRectMake(0.0, -40.0, 740.0, 1070.0); } } 

对于iOS6 +,您可以将其添加到您的控制器:

 - (BOOL)shouldAutorotate { YES; } - (NSUInteger)supportedInterfaceOrientations { if (<PDF is portrait>) return UIInterfaceOrientationMaskPortrait; if (<PDF is landscape>) return UIInterfaceOrientationMaskLandscape; return UIInterfaceOrientationMaskAll; } 

希望这可以帮助。

编辑:

我不确定是否需要手动旋转PDF以获得所需的结果。 在这种情况下,你可以试试类似的东西:

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation duration:(NSTimeInterval)duration { if (toOrientation == UIInterfaceOrientationMaskLandscape) pdfScrollViewFrame.transform = CGAffineTransformMakeRotation(M_PI/2); … // handle all other cases here } 

为了只lockingviewDidAppear后的旋转,我会做以下事情:

 @interface… … @property (nonatomic) BOOL isRotationLocked; … @end @implementation… … - (void)viewDidAppear:(BOOL)animated { … self.isRotationLocked = YES; } - (BOOL)shouldAutorotate { YES; } - (NSUInteger)supportedInterfaceOrientations { if (self.isRotationLocked) { if (<PDF is portrait>) return UIInterfaceOrientationMaskPortrait; if (<PDF is landscape>) return UIInterfaceOrientationMaskLandscape; } return UIInterfaceOrientationMaskAll; } …