高仿微信,QQ图片上传,包括相机,相册选择图片

高仿微信,QQ图片上传,包括相机,相册选择图片_第1张图片
图片选择1.gif
高仿微信,QQ图片上传,包括相机,相册选择图片_第2张图片
图片选择2.gif

简述

借助PYPhotoBrowserYangMingShan共同组合成图片选择和图片展示的实用开发功能。

介绍

PYPhotoBrowser:图片未发布之前,图片本地预览和删除。
YangMingShan:相册选择访问,相机使用。

使用方法

创建PYPhotosView(九宫格类型/直线类型)
PYPhotosView *squPhotosView = [PYPhotosView photosView];
squPhotosView.photosState = PYPhotosViewStateWillCompose;
squPhotosView.photoWidth =  80;
squPhotosView.photoHeight = 80;
squPhotosView.py_x = 20;
squPhotosView.py_y = 100;
squPhotosView.delegate = self;
[self.view addSubview:squPhotosView];

PYPhotosView *recPhotosView = [PYPhotosView photosView];
recPhotosView.photosState = PYPhotosViewStateWillCompose;
recPhotosView.photosMaxCol = 9;
recPhotosView.photoWidth = 80;
recPhotosView.photoHeight = 80;
recPhotosView.py_x = 20;
recPhotosView.py_y = 300;
recPhotosView.delegate = self;
[self.view addSubview:recPhotosView];
PYPhotosView代理方法请求打开相册相机
- (void)photosView:(PYPhotosView *)photosView didAddImageClickedWithImages:(NSMutableArray *)images {
    [self yms_presentCustomAlbumPhotoView:self.pickerViewController delegate:self];
}
访问相机相册
-(void)photoPickerViewControllerDidReceivePhotoAlbumAccessDenied:(YMSPhotoPickerViewController *)picker {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"允许访问相册?" message:@"需要你的允许访问相册" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    [alertController addAction:dismissAction];
    [alertController addAction:settingsAction];
    [self presentViewController:alertController animated:YES completion:nil];
}

- (void)photoPickerViewControllerDidReceiveCameraAccessDenied:(YMSPhotoPickerViewController *)picker {
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"允许访问相机?" message:@"需要你的允许访问相机" preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction *dismissAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    UIAlertAction *settingsAction = [UIAlertAction actionWithTitle:@"去设置" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
    }];
    [alertController addAction:dismissAction];
    [alertController addAction:settingsAction];
    [picker presentViewController:alertController animated:YES completion:nil];
}
获得选中照片
- (void)photoPickerViewController:(YMSPhotoPickerViewController *)picker didFinishPickingImages:(NSArray *)photoAssets {
    [picker dismissViewControllerAnimated:YES completion:^() {
        PHImageManager *imageManager = [[PHImageManager alloc] init];
        PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init];
        options.deliveryMode = PHImageRequestOptionsDeliveryModeHighQualityFormat;
        options.networkAccessAllowed = YES;
        options.resizeMode = PHImageRequestOptionsResizeModeExact;
        options.synchronous = YES;
        NSMutableArray *mutableImages = [NSMutableArray array];
        for (PHAsset *asset in photoAssets) {
            [imageManager requestImageDataForAsset:asset options:options resultHandler:^(NSData * _Nullable imageData, NSString * _Nullable dataUTI, UIImageOrientation orientation, NSDictionary * _Nullable info) {
                [mutableImages addObject:[UIImage imageWithData:imageData]];
            }];
        }
        [self.recPhotosView setImages:mutableImages]; //将照片赋值给PhotosView
    }];
}
注意:1.在plist文件中添加获取相册相机权限字段。2.需要所有图片上传时,通过自定义photoView.images获得。3.pickerViewController自定义请查看YangMingShan

你可能感兴趣的:(高仿微信,QQ图片上传,包括相机,相册选择图片)