- 我打开了,获取僵尸对象,报的错是
PUUIImageViewController retain
.
#pragma mark 修改头像
- (void)avatarChangeOnClicked {
UIAlertController *alterController = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cameraAction = [UIAlertAction actionWithTitle:@"相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self openCamera];
}];
UIAlertAction *albumAction = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
[self openAlbum];
}];
UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
}];
[alterController addAction:cameraAction];
[alterController addAction:albumAction];
[alterController addAction:cancelAction];
[self presentViewController:alterController animated:YES completion:nil];
}
- (void)openCamera {
[self openImagePickerController:UIImagePickerControllerSourceTypeCamera];
}
- (void)openAlbum {
// 如果想自己写一个图片选择控制器,得利用AssetsLibrary.framework,利用这个框架可以获得手机上的所有相册图片
// UIImagePickerControllerSourceTypePhotoLibrary > UIImagePickerControllerSourceTypeSavedPhotosAlbum
[self openImagePickerController:UIImagePickerControllerSourceTypePhotoLibrary];
}
- (void)openImagePickerController:(UIImagePickerControllerSourceType)type {
if (![UIImagePickerController isSourceTypeAvailable:type]) return;
if (type == UIImagePickerControllerSourceTypeCamera) {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
if ([[AVCaptureDevice class] respondsToSelector:@selector(authorizationStatusForMediaType:)]) {
AVAuthorizationStatus authorizationStatus = [AVCaptureDevice authorizationStatusForMediaType:AVMediaTypeVideo];
if (authorizationStatus == AVAuthorizationStatusRestricted
|| authorizationStatus == AVAuthorizationStatusDenied) {
// 没有权限
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil
message:@"没有权限访问相机,您可以在 (设置 > 隐私 > 相机)打开应用访问权限,即可自定义图片!"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
return;
}
}
}
}
UIImagePickerController *ipc = [[UIImagePickerController alloc] init];
ipc.delegate = self;
ipc.allowsEditing = YES;
ipc.sourceType = type;
[self presentViewController:ipc animated:YES completion:nil];
}
#pragma mark - UIImagePickerControllerDelegate
/**
* 从UIImagePickerController选择完图片后就调用(拍照完毕或者选择相册图片完毕)
*/
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
/*
==<PUUIAlbumListViewController: 0x1360eae00>
==<PUUIPhotosAlbumViewController: 0x135a3a000>
==<PUUIImageViewController: 0x137574330>
-[PUUIImageViewController retain]
*/
for (UIViewController *vc in [picker viewControllers]) {
Class class = NSClassFromString(@"PUUIImageViewController");
if ([vc isKindOfClass:class]) {
[self addChildViewController:vc];
}
}
[picker dismissViewControllerAnimated:YES completion:nil];
// info中就包含了选择的图片
UIImage *editImage = info[UIImagePickerControllerEditedImage];
self.avatarImageView.image = editImage;
// 上传头像
[self avatarChangeFromImage:editImage];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
参考链接
网友评论