UIImagePicker允许Editing卡在中心

我有一个UIImagePicker完美的UIImagePickerControllerSourceTypePhotoLibrarytypes,但是当我使用UIImagePickerControllerSourceTypeCamera,编辑框不能从图像的中心移动。 因此,如果图像比宽度大,用户不能将编辑框移动到图像的上方。

任何人都知道为什么会这样? 它只发生在来源是相机而不是图书馆。

编辑:一些代码!

if (actionSheet.tag == 2) { if (buttonIndex == 0) { // Camera // Check for camera if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) { // Create image picker controller UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; // Set source to the camera imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; imagePicker.allowsEditing = YES; // Delegate is self imagePicker.delegate = self; // Show image picker [self presentViewController:imagePicker animated:YES completion:^(void) { }]; } } else if (buttonIndex == 1) { // Photo Library if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == YES) { // Create image picker controller UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init]; // Set source to the camera imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; imagePicker.allowsEditing = YES; // Delegate is self imagePicker.delegate = self; // Show image picker [self presentViewController:imagePicker animated:YES completion:^(void) { }]; } } 

所以,正如你所看到的,我显示他们完全相同,但相机编辑行为不同于照片库编辑。

4 Solutions collect form web for “UIImagePicker允许Editing卡在中心”

看起来这个行为只是iOS 6中的一个bug …基本上你不能移动编辑框,除非放大一点,否则它总是会弹回到中间位置。 希望他们尽快解决。

这是图像select器控制器的默认行为,您不能更改它。 唯一的其他select是创build您自己的裁剪实用程序。 查看下面的链接举例:

https://github.com/ardalahmet/SSPhotoCropperViewController

我知道,这不是一个好的解决scheme,但它的工作原理。

我在iOS8 + iPhone5,iOS9 + iPhone6sPlus,iOS10 + iPhone6,iOS10 + iPhone6sPlus上testing。

小心PLImageScrollViewPLCropOverlayCropViewPLCropOverlayCropView类。

 - (void)showImagePickerControllerWithSourceType:(UIImagePickerControllerSourceType)sourceType { UIImagePickerController *imagePickerController = [UIImagePickerController new]; imagePickerController.sourceType = sourceType; imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage]; imagePickerController.allowsEditing = YES; imagePickerController.delegate = self; [self presentViewController:imagePickerController animated:YES completion:^{ [self fxxxImagePickerController:imagePickerController]; }]; } - (void)fxxxImagePickerController:(UIImagePickerController *)imagePickerController { if (!imagePickerController || !imagePickerController.allowsEditing || imagePickerController.sourceType != UIImagePickerControllerSourceTypeCamera) { return; } // !!!: UNDOCUMENTED CLASS Class ScrollViewClass = NSClassFromString(@"PLImageScrollView"); Class CropViewClass = NSClassFromString(@"PLCropOverlayCropView"); [imagePickerController.view eachSubview:^BOOL(UIView *subview, NSInteger depth) { if ([subview isKindOfClass:CropViewClass]) { // 0. crop rect position subview.frame = subview.superview.bounds; } else if ([subview isKindOfClass:[UIScrollView class]] && [subview isKindOfClass:ScrollViewClass]) { BOOL isNewImageScrollView = !self->_imageScrollView; self->_imageScrollView = (UIScrollView *)subview; // 1. enable scrolling CGSize size = self->_imageScrollView.frame.size; CGFloat inset = ABS(size.width - size.height) / 2; self->_imageScrollView.contentInset = UIEdgeInsetsMake(inset, 0, inset, 0); // 2. centering image by default if (isNewImageScrollView) { CGSize contentSize = self->_imageScrollView.contentSize; if (contentSize.height > contentSize.width) { CGFloat offset = round((contentSize.height - contentSize.width) / 2 - inset); self->_imageScrollView.contentOffset = CGPointMake(self->_imageScrollView.contentOffset.x, offset); } } } return YES; }]; // prevent re-layout, maybe not necessary @weakify(self, imagePickerController); dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ @strongify(self, imagePickerController); [self fxxxImagePickerController:imagePickerController]; }); } 

编辑eachSubview:方法遍历所有子视图树。

解决这个问题的解决方法是在info.plist中添加一个条目,将“ 基于视图控制器的状态栏外观 ”设置为NO

  • 我可以从URL加载UIImage?
  • 自定义视图的相机
  • 在横向上使用UIImagePickerController
  • UIImagePickerController摄像头视图在iOS 8上奇怪的旋转(图片)
  • Xcode 8 - 创build一个未知types的图像格式是一个错误
  • iOS 8 SDK:模态UIWebView和相机/图像select器
  • 上传后iOS iOS UIImagePickerController结果图像方向
  • UIImagePickerController错误:快照未呈现的视图会导致iOS 7中的空快照
  • 什么时候应该使用UIImagePickerControllerSourceTypePhotoLibrary而不是UIImagePickerControllerSourceTypeSavedPhotosAlbum?
  • 设置UIImagePickerController“移动和缩放”裁剪框的尺寸
  • UIImagePickerController不填充屏幕