Landscape中的UIImagePickerController

PF1*_*PF1 23 iphone cocoa-touch landscape image uiimagepickercontroller

我一直在寻找答案,但无法想出任何答案.显然,iPhone SDK 3.0使得UIImagePickerController可以以横向模式显示 - 但我找不到任何允许这样做的方法.我认为如果应用程序默认情况下是横向的,它会自动调整图像控制器,但这对我不起作用.

谢谢你的帮助!

Ari*_*sky 15

不需要子类; 简单地覆盖modalPresentationStyle属性.

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationFormSheet;
    [viewController presentViewController:picker animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)

  • 我会把这作为公认的答案.使用`picker.modalPresentationStyle = UIModalPresentationCurrentContext;`以获得更好的结果. (4认同)

era*_*uki 13

我没有检查这是否违法,但它对我有用.如果您希望UIImagePickerController以横向方向代码启动(并保持):

//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];
Run Code Online (Sandbox Code Playgroud)

方法didRotate:

- (void) didRotate:(NSNotification *)notification

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

}
Run Code Online (Sandbox Code Playgroud)

  • "这会给你一个警告.我忽略了它." 但是,对于使用未记录的API,Apple可能不会那么高兴 (6认同)
  • 我设法让拾取器出现在风景中,但相机(实时)图像旋转90°,所以你无法真正使用它来拍摄任何照片,就好像你将iPhone水平移动一样,你会看到垂直移动相机屏幕/图像,反之亦然.别人是否面临这个问题,甚至还有解决方法?在此先感谢您的帮助!:) (6认同)

use*_*592 8

如果你只是需要摆脱警告尝试

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end
Run Code Online (Sandbox Code Playgroud)