我一直在寻找这个问题的答案,但什么都想不出来。显然,iPhone SDK 3.0 使得 UIImagePickerController 可以在横向模式下显示 - 但我没有找到任何允许这样做的方法。我认为如果应用程序默认处于横向状态,它会自动调整图像控制器,但这对我不起作用。
谢谢你的帮助!
我一直在寻找这个问题的答案,但什么都想不出来。显然,iPhone SDK 3.0 使得 UIImagePickerController 可以在横向模式下显示 - 但我没有找到任何允许这样做的方法。我认为如果应用程序默认处于横向状态,它会自动调整图像控制器,但这对我不起作用。
谢谢你的帮助!
无需子类;只需覆盖该modalPresentationStyle
属性。
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.modalPresentationStyle = UIModalPresentationFormSheet;
[viewController presentViewController:picker animated:YES completion:NULL];
我没有检查这是否非法,但它对我有用。如果您希望 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];
}
如果您只需要摆脱警告,请尝试
@interface UIDevice ()
-(void)setOrientation:(UIDeviceOrientation)orientation;
@end
我在横向模式下开发了一个 UIImagePicker 类。适用于我开发的应用程序:希望它也适用于您:
GitHub:https ://github.com/imaginaryunit/iOSLandscapeThreadedImagePicker.git
我也有一个使用 UIImagePickerController 的全景观应用程序。请注意,如果您在横向模式下调用 UIImagePickerController,您的应用可能会被 Apple Review Team 拒绝。
我针对这个问题设计了一个简单的工作,它使用了 shouldAutoRotate 委托。Apple 批准将此方法用于全横向应用程序。
有关详细信息和可下载的完整项目源代码,请参见此处。
制作一个UINavigationController的类别并添加此方法
- (BOOL)shouldAutorotate
{
return NO;
}
子类化UIImagePickerController
和覆盖modalPresentationStyle
如下:
- (UIModalPresentationStyle)modalPresentationStyle
{
if([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
{
return UIModalPresentationFormSheet;
}
return [super modalPresentationStyle];
}
图像选择器现在是一个表单,不再处于全屏模式,但在横向模式下看起来不错。这应该是完全应用商店安全的。
这适用于画廊,不适用于拍照。
我解决了这个问题如下:每次改变方向后,我简单地重新创建选择器。试试这个。不同的是太歪了……
我正在开发一个尽力在横向模式下工作的课程。在 GitHub 上查看:RACameraController