Using UIImagePickerController in landscape orientation

后端 未结 8 634
暗喜
暗喜 2020-11-28 09:55

I am creating an app which is in landscape mode and I am using UIImagePickerController to take photos using iPhone camera in it and I want to create it in lands

8条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-28 10:25

    Try this way....

    As per Apple Document, ImagePicker Controller never Rotate in Landscape mode. You have to use in Portrait Mode only.

    For disable Landscape mode only for ImagePicker Controller follow below code:

    In your ViewController.m:

    Make the SubClass(NonRotatingUIImagePickerController) of Image Picker Controller

    @interface NonRotatingUIImagePickerController : UIImagePickerController
    
    @end
    
    @implementation NonRotatingUIImagePickerController
    // Disable Landscape mode.
    - (BOOL)shouldAutorotate
    {
        return NO;
    }
    @end
    

    Use as follow

    UIImagePickerController* picker = [[NonRotatingUIImagePickerController alloc] init];
            picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            picker.delegate = self; 
      etc.... Just as Default ImagePicker Controller
    

    This is working for me & Let me know if you have any Problem.

提交回复
热议问题