拍照时UIImagePicker错误旋转

时间:2013-10-13 19:11:35

标签: ios objective-c uiimagepickercontroller

我正在尝试用我的iPad应用拍照,但是当我启动UIImagePickerController时,相机会以错误的方向显示图像。

这是我调用UIImagePickerController的代码:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0 || buttonIndex == 1) {
        // Initialization
        self.imgPicker = [[UIImagePickerController alloc] init];
        self.imgPicker.allowsEditing = YES;
        self.imgPicker.delegate = self;

        // Chosing the source
        if (buttonIndex == 0) {
            self.imgPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; // Displayed in the good orientation
        }
        else {
            self.imgPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
            self.imgPicker.showsCameraControls = YES;
        }

        // Popup pour la photo
        self.imgPicker.allowsEditing = YES;
        self.imgPicker.contentSizeForViewInPopover = CGSizeMake(1000, 700);
        self.photoPopOver.delegate = self;
        self.photoPopOver = [[UIPopoverController alloc] initWithContentViewController:self.imgPicker];
        [self.photoPopOver presentPopoverFromRect:self.photoBut.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
    }
    else {
        [self cancel];
    }
}

要了解的事项: - 当我将sourceType设置为UIImagePickerControllerSourceTypePhotoLibrary时,视图会正确显示 - 拍摄照片时,它会以良好的旋转显示

我不知道如果它有用,但在父视图控制器中,我有这个:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    return UIInterfaceOrientationIsLandscape(toInterfaceOrientation);
}

- (BOOL)shouldAutorotate {
    return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

我该如何解决?非常感谢!

2 个答案:

答案 0 :(得分:1)

//此解决方案用于修复使用UIImage或相机挑选的UIImagePickerViewController方位。

以下是修复方向问题check out here

的示例

定义了一个类别来修复IOS中的方向问题。如果您在IOS设备中使用“相机”应用程序在“纵向”模式下拍照,然后通过UIImagePickerViewController在应用程序中使用它,则会发生这种情况,因为相机的默认方向为Landscape

答案 1 :(得分:0)

听起来更像是因为相机预览的方向与拍摄的图像不正确。 Here is some code to fix your problem.