Force landscape orientation in UIImagePickerController

前端 未结 3 973
耶瑟儿~
耶瑟儿~ 2020-11-27 21:11

I\'m new to iOS development, and Im developing my first app. (so sorry if Im asking a newbie question)

My app is all in portrait orientation, except to the place whe

相关标签:
3条回答
  • 2020-11-27 21:32

    try implementing below methods:

    - (BOOL)shouldAutorotate
    {
    
    return YES;
    }
    
    -(NSUInteger)supportedInterfaceOrientations
    
    {
    return UIInterfaceOrientationMaskLandscape;
    
    }
    
    - (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
    {
      return UIInterfaceOrientationLandscapeRight;
    }
    
    0 讨论(0)
  • 2020-11-27 21:41

    Create a class named "CUIImagePickerController" inherited from UIImagePickerController, override following methods, now use this class!

    @interface CUIImagePickerController : UIImagePickerController
    
    @end
    
    @implementation CUIImagePickerController
    - (BOOL)shouldAutorotate {
        return NO;
    }
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
        return (orient == UIInterfaceOrientationLandscapeLeft) | (orient == UIInterfaceOrientationLandscapeRight);
    }
    @end
    

    Regards,

    0 讨论(0)
  • 2020-11-27 21:48

    As per the UIImagePickerController Class Reference

    Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

    So it looks like forcing landscape mode is unsupported and discouraged, unless you do so by replacing the default controls with a custom cameraOverlayView.

    0 讨论(0)
提交回复
热议问题