禁用iOS中的相机旋转?

时间:2014-07-15 11:56:35

标签: ios camera rotation uiimagepickercontroller autorotate

我添加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中解决此问题。

P.S。我知道有很多争论,但似乎它们太旧了,因为它们没有任何作用。

2 个答案:

答案 0 :(得分:0)

当你实例化UIImagePickerController时,你也必须传递一个委托。代表应符合2个协议UIImagePickerControllerDelegateUINavigationControllerDelegate。第二种可以在运行时添加一些旋转逻辑,相应地实现这些方法以实现你想要实现的目标。

– navigationControllerPreferredInterfaceOrientationForPresentation:
– navigationControllerSupportedInterfaceOrientations:

答案 1 :(得分:0)

我更改了以下代码:

imgView.image = img;

为:

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

现在它适用于iOS 6和7.我不知道如何解决这个问题,但它确实有效。也许图像选择器会破坏图像或图像视图,并且此代码通过创建新的图像实例来修复它。