强制UIImagePickerController横屏显示

12

我是iOS开发的新手,正在开发我的第一个应用程序。(如果我问了一些新手问题,请多多包涵)

我的应用程序全部采用竖直方向,只有在使用UIImagePickerController拍摄照片以供应用程序使用时才会切换方向,我所做的是:

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeImage];
picker.allowsEditing = NO;
[self presentModalViewController:picker animated:YES];

由于我的应用程序是以纵向模式显示的,因此我需要使< strong>UIImagePickerController 只能在横向模式下使用。如果我尝试使用以下代码:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

似乎我不能使用这个,因为我的Xcode在这些行中识别出了一个错误(可能是因为Xcode的版本,我不确定)。而且我也不确定,但似乎如果我为iOS 5.1进行开发,我还需要实现一些东西用于iOS 6.0,这正确吗?

有人能帮我理解一下如何使这个UIImagePickerController(仅应用程序中的此视图控制器)在横向方向上工作,并在iOS 5.1和6中工作吗?

问候


你正在使用这个吗?http://developer.apple.com/library/ios/#documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/preferredInterfaceOrientationForPresentation - Nitin Alabur
3个回答

14
根据UIImagePickerController类参考UIImagePickerController类仅支持纵向模式。该类旨在按原样使用,不支持子类化。该类的视图层次结构是私有的,除了一种情况外,不能修改。您可以将自定义视图分配给cameraOverlayView属性,并使用该视图呈现其他信息或管理相机接口与您的代码之间的交互。因此,除非通过替换默认控件来实现,否则不支持和不鼓励强制横向模式。

1
创建一个名为"CUIImagePickerController"的类,继承自UIImagePickerController,在此基础上重写以下方法,现在使用这个类!
@interface CUIImagePickerController : UIImagePickerController

@end

@implementation CUIImagePickerController
- (BOOL)shouldAutorotate {
    return NO;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)orient {
    return (orient == UIInterfaceOrientationLandscapeLeft) | (orient == UIInterfaceOrientationLandscapeRight);
}
@end

敬礼,

1
也许是因为我的设备运行的是iOS 6? - Fernando
7
禁止继承UIImagePickerController ;) - raistlin
2
@raistlin 不,这并不是被禁止的。我已经这样做了好几年了。 - rmaddy

-1

尝试实现以下方法:

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeRight;
}

我尝试过了,但它只旋转拍照按钮,而相机图像甚至在拍照之前就旋转了,显示非常奇怪。有什么想法吗? - Fernando

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接