Using UIImagePickerController in landscape orientation

后端 未结 8 702
暗喜
暗喜 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:19

    ... and I want to create it in landscape mode too.

    One line of code can make a big difference! In the method or function where your IBAction lands:

    In Swift,

    let imagePickerController = UIImagePickerController()
    imagePickerController.delegate = self
    // .overCurrentContext allows for landscape and portrait mode
    imagePickerController.modalPresentationStyle = .overCurrentContext
    

    Objective-C,

    UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
    [imagePickerController setDelegate:self];
    [imagePickerController setModalPresentationStyle: UIModalPresentationOverCurrentContext];
    

    Note: This will allow imagePickerController to present it's view correctly, but will may not fix the issue of rotation while it is presented.

提交回复
热议问题