简体   繁体   中英

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

Why not creating 2 or even 4 UIImagePickerController s 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.

Try this assign properties in view did load , not in imageCaptured method. it works fine

 videoController.delegate = self;
    videoController.sourceType =UIImagePickerControllerSourceTypePhotoLibrary;
    videoController.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:videoController.sourceType];
    videoController.allowsEditing = YES;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM