【问题标题】:Disable camera rotation in iOS?在iOS中禁用相机旋转?
【发布时间】:2014-07-15 11:56:35
【问题描述】:

我添加 UIImagePickerController 的代码:

picker = [[[UIImagePickerController alloc] init] autorelease];
    picker.delegate = self;
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    picker.showsCameraControls = NO;
    [self displayContentController:picker inView:cameraBoxView];
    [self.view sendSubviewToBack:picker.view];

- (void)displayContentController:(UIViewController *)content inView:(UIView *)v {

    //Delete the previous instance of the same view controller
    for (UIViewController *vc in self.childViewControllers) {

        if ([vc isKindOfClass:[content class]]) {

            [vc removeFromParentViewController];
        }
    }

    [self addChildViewController:content];
    content.view.frame = v.frame;
    [self.view addSubview:content.view];
    [content didMoveToParentViewController:self];

    if ([content isKindOfClass:[CCInnerNavigationController class]]) {

        innerNavigationController = (CCInnerNavigationController *)content;
    }
}

我已禁用除纵向之外的所有设备方向。但是来自相机的图像是旋转的。如何在 iOS 6 和 7 中解决此问题。

附:我知道有很多解决方案,但它们似乎太旧了,因为它们都不起作用。

【问题讨论】:

    标签: ios camera rotation uiimagepickercontroller autorotate


    【解决方案1】:

    当您实例化 UIImagePickerController 时,您还必须向它传递一个委托。委托应符合UIImagePickerControllerDelegateUINavigationControllerDelegate 2 个协议。第二个可以在运行时添加一些旋转逻辑,根据您想要实现的实现这些方法。

    – navigationControllerPreferredInterfaceOrientationForPresentation:
    – navigationControllerSupportedInterfaceOrientations:
    

    【讨论】:

    • NS_AVAILABLE_IOS(7_0);两者都适用......即使它们在 iOS 7 中工作,我也需要适用于 iOS 6 的解决方案
    • ooopsss... 即使我不喜欢 UIImagePikerController 上的某个类别似乎是一个解决方案stackoverflow.com/questions/8940443/…
    • 他们的解决方案不起作用:我仍然得到旋转的图像。似乎他们的最佳答案应该有效,但我不知道如何正确应用它
    • 另外,我尝试在所有应用程序中启用自动旋转。我看到选择器的旋转是纵向的,但结果是旋转的。这意味着如果设备处于横向,那么当我向上/向下移动设备时,预览图片会向左/向右移动
    • 就我所读到的而言,Camera v.c.只是肖像只是改变的界面(和图像元数据)
    【解决方案2】:

    我更改了以下代码:

    imgView.image = img;
    

    到:

    imgView.image = [UIImage imageWithCGImage:img.CGImage scale:1 orientation:UIImageOrientationRight];
    

    现在它可以在 iOS 6 和 7 中使用。我不知道它是如何修复这个错误的,但它确实有效。也许图像选择器损坏了图像或图像视图,这段代码通过创建一个新的图像实例来修复它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-01-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-03-04
      • 2021-03-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多