如何使用自定义覆盖按钮从相机访问相机胶卷

时间:2013-10-11 02:42:18

标签: ios camera ios7

我有一个UIImagePicker控制器,有一个按钮叠加,可以翻转相机,拍照等,我希望其中一个可以访问相机胶卷。按下按钮时,我希望相机胶卷打开,当用户选择照片时,它应该开始didFinishPickingMediaWithInfo。我有这个:

UIImage *cameraRoll = [UIImage imageNamed:@"cameraroll_icon"];

UIButton *cameraRollButton = [UIButton buttonWithType:UIButtonTypeCustom];
cameraRollButton.frame = CGRectMake(250, 0, 48, 30);
[cameraRollButton setImage:cameraRoll forState:UIControlStateNormal];

[cameraRollButton addTarget:self action:@selector(accessCameraRoll:) forControlEvents:UIControlEventTouchUpInside];

[overlay addSubview:cameraRollButton];

// accessCameraRoll

-(IBAction)accessCameraRoll:(id)sender {

// What do I put here to get camera roll for self.imagePicker?


}

1 个答案:

答案 0 :(得分:0)

请尝试以下操作,让我们知道会发生什么:)

-(IBAction)accessCameraRoll:(id)sender {

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