Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ArtOfWarfare

macrumors G3
Original poster
Nov 26, 2007
9,695
6,270
When picking an image with a UIImagePickerViewController, a crop box like in the attached image shows up.

I don't want to force the user to pick a square image. I'd rather let the user pick their own aspect ratio, if easily possible, or if not, I want it to just use the original aspect ratio of the image.

I looked for anything relevant in the documentation for UIImagePickerViewController but found nothing.

Here's the code I'm using to configure and display the image picker:

Code:
- (void)insertVisual:(UIImagePickerControllerSourceType)sourceType {
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    imagePicker.sourceType = sourceType;
    imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:sourceType];
    imagePicker.allowsEditing = YES;
    imagePicker.delegate = self;
    [self.viewController presentViewController:imagePicker animated:YES completion:NULL];
}

(This gets called from elsewhere with either UIImagePickerControllerSourceTypeCamera or UIImagePickerControllerSourceTypePhotoLibrary, based on what button the user presses in my view controller.)

This probably isn't relevant but just incase, here's my implementation for the delegate callbacks:

Code:
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self.viewController dismissViewControllerAnimated:YES completion:NULL];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    NSLog(@"Something was picked, now it needs to be inserted inline. This hasn't been implemented yet...");
    [self.viewController dismissViewControllerAnimated:YES completion:NULL];
}

Also probably an unnecessary detail, but just incase, these are methods of a subclass of a UITextView, not of a UIViewController. I realize this is violation of MVC, but this seemed like the best way to go since I wanted the pickers to come up based on touches in a UIMenuController. Thus the spots where I have self.viewController.

Those invoke this code:

Code:
- (UIViewController *)viewController {
    UIResponder *responder = self.nextResponder;
    while (responder != nil && ![responder isKindOfClass:UIViewController.class]) {
        responder = responder.nextResponder;
    }
    return (UIViewController *)responder;
}

But I think that's probably completely unrelated to my problem. My problem is probably in my configuration of the UIImagePickerController in the very beginning of my post.
 

Attachments

  • CropBox.png
    CropBox.png
    956.5 KB · Views: 1,091
Last edited:
Searching around, I see there's something called AVCaptureVideoPreviewLayer, but that looks like it's a lower level API which I don't think I should need for something that seems like such a simple requirement as not having a crop box.

I also tried the second solution listed here:
http://www.ggkf.com/iphone/change-uiimagepicker-aspect-ratio

This didn't change anything... plus it looks like that relates to the picture-taking screen anyways, not the preview screen.

Edit: Acceptable Fallback Found
I found this answer which clearly states that the problem is because I have allowEditing set to true. I set it to false and it removes the editing screen altogether - an acceptable fall back.
 
Last edited:
Ehm, you don't want the square box? So that the user won't be making square images?

I'm using the original pickerview for camera and I'm not getting any square box. (From the documentation I used this code)

Code:
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
  UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
  imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
  imagePicker.mediaTypes = @[(NSString *) kUTTypeImage];
  imagePicker.allowsEditing = NO;
  [imagePicker setDelegate: self];
  [self presentViewController:imagePicker animated:YES completion:nil];
}

Indeed I disabled allowsEditing
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.