Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIImagePickerController allowsEditing=YES just for video

I am using the UIImagePickerController to let the user select a photo or video. The problem I am facing, is I use my own image editor for photo's so want allowsEditing=NO for photo's, but video must be a certain length so I want allowsEditing=YES for video.

Setting videoMaximumDuration for the image picker works fine when recording video, but if selecting from the camera roll it only informs the user that the video is too long if allowsEditing is enabled.

So far, I can successfully change the allowsEditing property when using the camera by listening for the ImageControlModeChanged notification. Then I can change the property using:

- (void)imageCaptured:(NSNotification *)notification
{
    if (imagePicker.cameraCaptureMode == UIImagePickerControllerCameraCaptureModeVideo) {
        imagePicker.allowsEditing = YES;
    } else {
        imagePicker.allowsEditing = NO;
    }
}

However this doesn't work when selecting from the Camera roll. I have monitored the notifications and can't see one that would be useful to change the allowsEditing property depending on which item was selected.

Is this even possible?

Thanks

like image 949
Darren Avatar asked Dec 04 '13 11:12

Darren


1 Answers

Why not creating 2 or even 4 UIImagePickerControllers instead of messing around with notifications?

- (void) useCamera
{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeCamera])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

- (void) useCameraRoll
{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:(NSString *) kUTTypeImage,nil];
        imagePicker.allowsEditing = NO;
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

- (void)videoRoll
{

    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];
        imagePicker.allowsEditing = YES;
        imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

- (void)vidCam
{
    if ([UIImagePickerController isSourceTypeAvailable:
         UIImagePickerControllerSourceTypeSavedPhotosAlbum])
    {
        UIImagePickerController *imagePicker =
        [[UIImagePickerController alloc] init];
        imagePicker.delegate = self;
        imagePicker.sourceType =
        UIImagePickerControllerSourceTypeCamera;
        imagePicker.mediaTypes = [NSArray arrayWithObjects:
                                  (NSString *) kUTTypeImage,
                                  nil];
        imagePicker.allowsEditing = NO;
        imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        [self presentViewController:imagePicker animated:YES completion:nil];
    }
}

Edit:

After better understanding of the question I don't think it's possible. There are a few notification you can use but those are not documented anywhere or working on iOS7. If that is really the case the best solution I can think of is to use a 3rd party such as github.com/andrei200287/SAVideoRangeSlider and allowsEditing = NO for everything.

like image 131
Segev Avatar answered Oct 31 '22 03:10

Segev