查看相册视频&照片&摄像头 2023-07-27

2023-07-26  本文已影响0人  iOS打怪升级
 TZImagePickerController *imagePicker = [[TZImagePickerController alloc] initWithMaxImagesCount:9 delegate:self];
    imagePicker.allowCameraLocation = NO;
    imagePicker.allowPickingVideo = NO;
    imagePicker.allowPickingImage = YES;
    imagePicker.allowCrop = YES;
    imagePicker.modalPresentationStyle = 0;
    imagePicker.showSelectBtn = NO;
//    imagePicker.cropRect = CGRectMake(12.5, (SCREEN_HEIGHT-(SCREEN_WIDTH-25))/2, SCREEN_WIDTH-25, SCREEN_WIDTH-25);
    imagePicker.scaleAspectFillCrop = YES;
    imagePicker.modalPresentationStyle = 0;
    [[self viewController] presentViewController:imagePicker animated:YES completion:nil];
#import <UIKit/UIKit.h>

@interface ViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
@property (nonatomic, strong) UIImagePickerController *imagePickerController;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.imagePickerController = [[UIImagePickerController alloc] init];
    self.imagePickerController.delegate = self;
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    self.imagePickerController.mediaTypes = @[(NSString *)kUTTypeMovie];
}

- (IBAction)selectVideoButtonTapped:(id)sender {
    [self presentViewController:self.imagePickerController animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<UIImagePickerControllerInfoKey,id> *)info {
    NSURL *videoURL = info[UIImagePickerControllerMediaURL];
    // 在这里处理获取到的视频URL
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end
 if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
    self.imagePickerController = [[UIImagePickerController alloc] init];
    self.imagePickerController.delegate = self;
    self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
}

上一篇下一篇

猜你喜欢

热点阅读