23

我一直在寻找这个问题的答案,但什么都想不出来。显然,iPhone SDK 3.0 使得 UIImagePickerController 可以在横向模式下显示 - 但我没有找到任何允许这样做的方法。我认为如果应用程序默认处于横向状态,它会自动调整图像控制器,但这对我不起作用。

谢谢你的帮助!

4

9 回答 9

15

无需子类;只需覆盖该modalPresentationStyle属性。

    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.modalPresentationStyle = UIModalPresentationFormSheet;
    [viewController presentViewController:picker animated:YES completion:NULL];
于 2014-09-23T19:34:42.203 回答
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];

方法 didRotate:

- (void) didRotate:(NSNotification *)notification

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

}
于 2010-01-27T14:29:26.433 回答
8

如果您只需要摆脱警告,请尝试

@interface UIDevice ()
    -(void)setOrientation:(UIDeviceOrientation)orientation;
@end
于 2011-04-11T21:08:36.883 回答
3

我在横向模式下开发了一个 UIImagePicker 类。适用于我开发的应用程序:希望它也适用于您:

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

于 2012-02-27T18:58:43.950 回答
2

我也有一个使用 UIImagePickerController 的全景观应用程序。请注意,如果您在横向模式下调用 UIImagePickerController,您的应用可能会被 Apple Review Team 拒绝。

我针对这个问题设计了一个简单的工作,它使用了 shouldAutoRotate 委托。Apple 批准将此方法用于全横向应用程序。

有关详细信息和可下载的完整项目源代码,请参见此处

于 2011-01-17T05:11:14.560 回答
2

制作一个UINavigationController的类别并添加此方法

- (BOOL)shouldAutorotate
{
    return NO;
}
于 2013-05-15T09:33:49.027 回答
2

子类化UIImagePickerController和覆盖modalPresentationStyle如下:

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

    return [super modalPresentationStyle];
}

图像选择器现在是一个表单,不再处于全屏模式,但在横向模式下看起来不错。这应该是完全应用商店安全的。

这适用于画廊,不适用于拍照。

于 2014-05-28T12:28:42.170 回答
0

我解决了这个问题如下:每次改变方向后,我简单地重新创建选择器。试试这个。不同的是太歪了……

于 2010-01-29T16:47:49.400 回答
0

我正在开发一个尽力在横向模式下工作的课程。在 GitHub 上查看:RACameraController

于 2013-10-09T11:59:10.200 回答