【问题标题】:Force landscape orientation in UIImagePickerController在 UIImagePickerController 中强制横向
【发布时间】:2013-01-15 03:03: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];

由于我的应用在 Portrait 中,我需要为 UIImagePickerController 制作一些内容,使其位于 landscape only 中。如果我尝试使用:

[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationLandscapeRight];

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

有人可以帮我了解制作这个 UIImagePickerController 需要什么,并且只有应用程序中的这个视图控制器可以横向工作并在 iOS 5.1 和 6 中工作?

问候

【问题讨论】:

标签: ios objective-c xcode orientation uiimagepickercontroller


【解决方案1】:

尝试实现以下方法:

- (BOOL)shouldAutorotate
{

return YES;
}

-(NSUInteger)supportedInterfaceOrientations

{
return UIInterfaceOrientationMaskLandscape;

}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
  return UIInterfaceOrientationLandscapeRight;
}

【讨论】:

  • 试过了,但是它只旋转按钮拍照,并且它旋转到甚至在拍照之前的相机图像,显示非常奇怪。有什么想法吗?
【解决方案2】:

创建一个继承自 UIImagePickerController 的名为“CUIImagePickerController”的类,重写以下方法,现在使用这个类!

@interface CUIImagePickerController : UIImagePickerController

@end

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

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

问候,

【讨论】:

  • 可能是因为我的设备运行的是 iOS 6?
  • 禁止子类化 UIImagePickerController ;)
  • @raistlin 不,这不是被禁止的。我已经做了很多年了。
【解决方案3】:

根据UIImagePickerController Class Reference

重要提示UIImagePickerController 类仅支持纵向模式。此类旨在按原样使用,不支持子类化。此类的视图层次结构是私有的,不得修改,但有一个例外。您可以将自定义视图分配给 cameraOverlayView 属性,并使用该视图来显示附加信息或管理相机界面和代码之间的交互。

因此,强制横向模式似乎不受支持且不鼓励,除非您通过将默认控件替换为自定义 cameraOverlayView 来这样做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-14
    • 1970-01-01
    • 2012-04-05
    • 1970-01-01
    相关资源
    最近更新 更多