UIImagePickerController allowEditing = YES仅用于视频

时间:2013-12-04 11:01:04

标签: ios video camera uiimagepickercontroller

我正在使用UIImagePickerController让用户选择照片或视频。我面临的问题是,我使用自己的图片编辑器拍照片,所以想要照片allowsEditing=NO,但视频必须有一定的长度,所以我想要allowsEditing=YES视频。

在录制视频时,设置videoMaximumDuration图像选择器可正常工作,但如果从相机胶卷中选择,则只会在启用allowsEditing时通知用户视频太长。

到目前为止,通过收听allowsEditing通知,我可以在使用相机时成功更改ImageControlModeChanged属性。然后我可以使用:

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

但是,从相机胶卷中选择时,这不起作用。我已经监控了通知,但看不到根据选择的项目更改allowsEditing属性有用的通知。

这甚至可能吗?

由于

2 个答案:

答案 0 :(得分:2)

为什么不创建2个甚至4个UIImagePickerController而不是搞乱通知?

- (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];
    }
}

修改

在更好地理解这个问题之后,我认为这是不可能的。您可以使用一些通知,但这些通知没有在任何地方记录或在iOS7上工作。如果确实如此,我能想到的最佳解决方案是使用第三方,例如github.com/andrei200287/SAVideoRangeSlider和allowsEditing = NO

答案 1 :(得分:-1)

试试这个 在视图中指定属性是否加载,而不是在imageCaptured方法中。它工作正常

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