UIImagePickerController in Landscape

血红的双手。 提交于 2019-11-26 05:26:43

问题


I have been searching for an answer to this, but cannot come up with anything. Apparently, iPhone SDK 3.0 made it possible that UIImagePickerController can be displayed in landscape mode - but I am not finding any method that will allow this. I would think that if the application is in landscape by default it would automatically adjust the image controller, but that is not working for me.

Thanks for any help!


回答1:


I haven't checked whether this is illegal, but it worked for me. If you want the UIImagePickerController to start(and stay) in Landscape orientation code:

//Initialize picker

UIImagePickerController * picker = [[UIImagePickerController alloc] init];
   picker.delegate = self;


//set Device to Landscape. This will give you a warning. I ignored it.
//warning: 'UIDevice' may not respond to '-setOrientation:'


[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

//Set Notifications so that when user rotates phone, the orientation is reset to landscape.
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

//Refer to the method didRotate:   
[[NSNotificationCenter defaultCenter] addObserver:self
              selector:@selector(didRotate:)
               name:@"UIDeviceOrientationDidChangeNotification" object:nil];

//Set the picker source as the camera   
picker.sourceType = UIImagePickerControllerSourceTypeCamera;

//Bring in the picker view   
[self presentModalViewController:picker animated:YES];

The method didRotate:

- (void) didRotate:(NSNotification *)notification

{
      //Maintain the camera in Landscape orientation
 [[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

}



回答2:


No need to subclass; simply override the modalPresentationStyle property.

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationFormSheet;
    [viewController presentViewController:picker animated:YES completion:NULL];



回答3:


If you just need to get rid of the warning try

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end



回答4:


I've developed a UIImagePicker class in landscape mode. Works great for applications I've developed: hope it works for you too:

GitHub: https://github.com/imaginaryunit/iOSLandscapeThreadedImagePicker.git




回答5:


I have an all-landscape app using UIImagePickerController too. Please be noted that if you call UIImagePickerController in Landscape mode, your app is possible to be rejected by Apple Review Team.

I devised a simple work around this issue which make use the shouldAutoRotate delegate. Apple approves this method for an all-landscape app.

See here for the details and downloadable full project source code.




回答6:


Make a category of UINavigationController and add this method

- (BOOL)shouldAutorotate
{
    return NO;
}



回答7:


Subclass UIImagePickerController and override modalPresentationStyle as follows:

- (UIModalPresentationStyle)modalPresentationStyle
{
    if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
    {
        return UIModalPresentationFormSheet;
    }

    return [super modalPresentationStyle];
}

The image-picker is a form-sheet now and no longer in fullscreen-mode, but it looks good in landscape-mode. This should be totally app-store-safe.

This works for the gallery, not for taking pictures.




回答8:


I solved this problem as follows: after each change in orientation, I simple re-create picker. Try this. Differently is too crooked...




回答9:


I am developing a class that tries its best to work in landscape mode. Check it out on GitHub: RACameraController



来源:https://stackoverflow.com/questions/2083672/uiimagepickercontroller-in-landscape

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