ios中跳转到本地相册右上的取消按钮怎么设置
展开全部
使用iOS开发原生技术:UIImagePickerController
(1)创建相册视图控制器
UIImagePickerController *imagePickVC = [[UIImagePickerController alloc] init];
// 设置代理对象
imagePickVC.delegate = self;
// 开启编辑模式
imagePickVC.allowsEditing = YES;
// 设置媒体类型
imagePickVC.mediaTypes = @[@"public.image"];
(2)判断打开的是相册还是摄像航头
if (buttonIndex == 0) {
imagePickVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
} else if (buttonIndex == 1) {
// 要打开摄像头
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
imagePickVC.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
iToast *itoast = [iToast makeText:@"当前设备不支持拍摄"];
[itoast show];
return;
}
}
(3)打开系统相册
[self presentViewController:imagePickVC animated:YES completion:nil];
(4)实现代理方法
//点击相册的取消按钮
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
//照片处理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary<NSString *,id> *)editingInfo;
(1)创建相册视图控制器
UIImagePickerController *imagePickVC = [[UIImagePickerController alloc] init];
// 设置代理对象
imagePickVC.delegate = self;
// 开启编辑模式
imagePickVC.allowsEditing = YES;
// 设置媒体类型
imagePickVC.mediaTypes = @[@"public.image"];
(2)判断打开的是相册还是摄像航头
if (buttonIndex == 0) {
imagePickVC.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
} else if (buttonIndex == 1) {
// 要打开摄像头
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront] || [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
imagePickVC.sourceType = UIImagePickerControllerSourceTypeCamera;
} else {
iToast *itoast = [iToast makeText:@"当前设备不支持拍摄"];
[itoast show];
return;
}
}
(3)打开系统相册
[self presentViewController:imagePickVC animated:YES completion:nil];
(4)实现代理方法
//点击相册的取消按钮
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
[picker dismissViewControllerAnimated:YES completion:nil];
}
//照片处理方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary<NSString *,id> *)editingInfo;
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询