T.J.
T.J.

Reputation: 3960

UIImagerPicker "Move and Scale" not working

I am using the image picker to take a photo and then go to the the editing screen. When the program gets to the editing screen although it says "Move and Scale" at the bottom, it does not allow me to move or scale the image. The controls appear to be dead. I moved overlay view to the top of the screen to be sure it is not interfering with the controls. Here is my code for setting up the image picker:

- (void)setupImagePicker:(UIImagePickerControllerSourceType)sourceType

{
    self.imagePickerController.sourceType = sourceType;

    if (sourceType == UIImagePickerControllerSourceTypeCamera)
    {
        self.imagePickerController.showsCameraControls = YES;
        if (self.imagePickerController.allowsEditing==FALSE) 
        {
            self.imagePickerController.allowsEditing = TRUE;
        }
    [self.imagePickerController.cameraOverlayView addSubview:self.view];
    }

    if (sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum)
    {
    }
}

What do I need to do to get the move and scale controls to work?

Upvotes: 1

Views: 3348

Answers (3)

Surender Rathore
Surender Rathore

Reputation: 845

At the time of initialization

UIImagePickerController  *imagepicker=[[UIImagePickerController alloc]init];
            imagepicker.delegate=self;
            imagepicker.allowsEditing = YES;
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
                imagepicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
            }

And in the delegate method you can get edited image with key UIImagePickerControllerEditedImage

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{


    UIImage *img=[info objectForKey:UIImagePickerControllerEditedImage];
}

Upvotes: 0

T.J.
T.J.

Reputation: 3960

Even though my overlay view was design as 320 wide x 44 high, the imagePicker cameraOverlayView is 320 x 480 by default covering image view "Move and Scale" drag and pinch gestures. I adjusted the size of the cameraOverlayView and "Move and Scale" began working. Here is the code for adding the cameraOverlayView (the overlay is self.view):

    CGRect overlayRect = self.view.frame;
    [self.imagePickerController.cameraOverlayView setFrame:overlayRect];
    [self.imagePickerController.cameraOverlayView addSubview:self.view];

Upvotes: 3

Peter Sarnowski
Peter Sarnowski

Reputation: 11970

You should create/present the UIImagePicker view more like this:

if (![UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerSourceTypeCamera])
{
    //no camera available, notify the user then exit before crashing the app
    return;
}

//display picker control (no release, assume ARC)
UIImagePickerController * uiimage_picker = [[UIImagePickerController alloc] init];
[uiimage_picker setSourceType:UIImagePickerControllerSourceTypeCamera];
[uiimage_picker setAllowsEditing:YES];

[uiimage_picker setDelegate: self];    
[self presentModalViewController:uiimage_picker animated:YES];

You don't have to use modal controller, you can have it as your subview, but this is the default way to present one.

Upvotes: 1

Related Questions