How to lock screen in portrait / landscape on iPhone?

My application supports all orientation, but in some cases I want to lock the screen in

portrait / landscape.

In my application, I have two types of pdf document.

one is in the portrait document, and the other is in the landscape document.

I want to open portrait document only in portrait mode, and landscape document in

only landscape.

I want to do this: if my application is open in landscape mode, and I click on

portrait document, so it should rotate in portrait mode and the same as for landscape, if

my application is open in portrait mode, and when I click on the landscape document,

you need to rotate or open the document only in the landscape.

hope i make you guys sorry my english hope you understand what i want please

I need your help.

Thank you in advance

here is my code:

- (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); } } 
+1
source share
1 answer

For iOS6 +, you can add this to your controller:

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

Hope this helps.

EDIT:

I'm not sure if you need to manually rotate the PDF file to get the desired results. In this case, you can try something like:

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

To block the rotation after viewDidAppear , I would do the following:

 @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; } โ€ฆ 
+2
source

Source: https://habr.com/ru/post/1437566/


All Articles