How to lock screen in portrait/landscape in iPhone?

一世执手 提交于 2019-11-29 08:48:41

For iOS6+, you could 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 am not sure if you need to manually rotate the PDF to get the results you want. In this case you might try with something like:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toOrientation
                            duration:(NSTimeInterval)duration {

    if (toOrientation == UIInterfaceOrientationMaskLandscape)
        pdfScrollViewFrame.transform = CGAffineTransformMakeRotation(M_PI/2);

    … // handle all other cases here
}

In order to only lock rotation after viewDidAppear, I would do 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;

}
…
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!