【问题标题】:UIImagePicker wrong rotation when taking a pictureUIImagePicker 拍照时旋转错误
【发布时间】:2013-10-13 19:11:35
【问题描述】:

我正在尝试用我的 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;
}

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

【问题讨论】:

    标签: ios objective-c uiimagepickercontroller


    【解决方案1】:

    // 解决方案是修复使用UIImagePickerViewController 或相机拾取的UIImage 的方向。

    这是一个解决方向问题的示例check out here

    定义了一个类别来解决 IOS 中的方向问题。当您在 IOS 设备中使用“相机”应用程序以纵向模式拍摄照片然后通过 UIImagePickerViewController 在您的应用程序中使用它时会发生这种情况,因为相机的默认方向是 Landscape

    【讨论】:

      【解决方案2】:

      这听起来更像是您遇到的问题是相机预览的方向不正确,而不是捕获的图像。 Here is some code to fix your problem.

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-10-12
        • 1970-01-01
        • 1970-01-01
        • 2013-10-03
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多