How to lock screen in portrait/landscape in iPhone?

前端 未结 1 1290
北恋
北恋 2020-12-18 15:50

My Application supports all orientation but in few cases i want to lock the screen in

portrait/landscape mode.

In my Application i have two kind of pdf docum

相关标签:
1条回答
  • 2020-12-18 16:12

    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;
    
    }
    …
    
    0 讨论(0)
提交回复
热议问题