gpt4 book ai didi

ios - UIImagePicker 拍照时旋转错误

转载 作者:行者123 更新时间:2023-11-28 22:24:32 27 4
gpt4 key购买 nike

我正在尝试使用我的 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 时, View 显示正确- 拍照时,以良好的旋转显示

我不知道告诉它是否有用,但在父 View Controller 中,我有这个:

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

- (BOOL)shouldAutorotate {
return YES;
}

- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}

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

最佳答案

//Solution is here to fix the Orientation of UIImage 的方向使用 UIImagePickerViewController 挑选或相机。

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

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

关于ios - UIImagePicker 拍照时旋转错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19349143/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com