【问题标题】:How to show UIImagePickerControllerSourceTypeCamera in Landscape instead of Portrait如何以横向而不是纵向显示 UIImagePickerControllerSourceTypeCamera
【发布时间】:2013-03-20 10:58:30
【问题描述】:

我正在开发 iPad 应用程序,当我们点击右栏按钮时,我正在执行如下操作:

    -(IBAction)camerabuttonAction:(id)sender
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
   picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.delegate = self;

    self.popoverController = [[UIPopoverController alloc] initWithContentViewController:picker];
   [self.popoverController presentPopoverFromRect:CGRectMake(50, -250, 500, 300) inView:appDelegate.splitview.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}

我的问题是,当我处于景观模式时,如果我单击按钮。相机以纵向模式显示(图像以反向模式显示)。但是,如果我摇动 iPad,它就会在 LandScape 中显示。

对于 ios6 中的方向,我使用以下方法,但我没有写任何与 UIImagePickerControllerSourceTypeCamera 相关的内容

    - (void)viewWillLayoutSubviews
{
if([self interfaceOrientation] == UIInterfaceOrientationPortrait||[self interfaceOrientation] ==UIInterfaceOrientationPortraitUpsideDown)
    {
}
    else if ([self interfaceOrientation] == UIInterfaceOrientationLandscapeLeft||[self interfaceOrientation] == UIInterfaceOrientationLandscapeRight)
    {
}

}

    -(NSUInteger)supportedInterfaceOrientations
{

    return UIInterfaceOrientationLandscapeLeft | UIInterfaceOrientationPortrait;
}

【问题讨论】:

    标签: iphone ios objective-c uiimagepickercontroller uiinterfaceorientation


    【解决方案1】:

    你不应该这样做。摘自 Apple 文档:

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

    在这里:http://developer.apple.com/library/ios/#documentation/uikit/reference/UIImagePickerController_Class/UIImagePickerController/UIImagePickerController.html

    【讨论】:

    • 但是,如果我将我的 ipad 肖像旋转到风景,那么相机会显示在 LandScape @Vincent Saluzzo
    • @Babul 是的,但这是苹果公司。如果您想正确并尊重 Apple 的建议,您必须使用AVFoundation.framework 来执行此操作。