美文网首页
查看相册视频&照片&摄像头 2023-07-27

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

作者: iOS打怪升级 | 来源:发表于2023-07-26 11:15 被阅读0次
    • 查看相册照片列表:采用TZImagePickerController 多了序号选中,系统默认的没有个数统计
     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];
    
    • 查看视频列表:sourceType = UIImagePickerControllerSourceTypePhotoLibrary; mediaTypes = @[(NSString *)kUTTypeMovie]
    #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
    
    • 调用相机:sourceType = UIImagePickerControllerSourceTypeCamera; mediaTypes = @[(NSString *)kUTTypeImage]
     if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
        self.imagePickerController = [[UIImagePickerController alloc] init];
        self.imagePickerController.delegate = self;
        self.imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imagePickerController.mediaTypes = @[(NSString *)kUTTypeImage];
    }
    
    

    相关文章

      网友评论

          本文标题:查看相册视频&照片&摄像头 2023-07-27

          本文链接:https://www.haomeiwen.com/subject/korkpdtx.html