UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"照片选取" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *actionCancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
UIAlertAction *actionAlbum = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *Imagepicker = [[UIImagePickerController alloc] init];
Imagepicker.delegate =self;
Imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:Imagepicker animated:YES completion:nil];
}
else{
[self.view makeToast:@"相册未发现"
duration:CLEAR_TIME
position:[NSValue valueWithCGPoint:CGPointMake([UIScreen mainScreen].bounds.size.width/2.f, [UIScreen mainScreen].bounds.size.height-160)]];
}
}];
UIAlertAction *actionCamera = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *picker =[[UIImagePickerController alloc] init];
picker.delegate =self;
// picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES
completion:^{
}];
}
else{
[self.view makeToast:@"摄像头未发现"
duration:CLEAR_TIME
position:[NSValue valueWithCGPoint:CGPointMake([UIScreen mainScreen].bounds.size.width/2.f, [UIScreen mainScreen].bounds.size.height-160)]];
}
}];
[alertController addAction:actionCancel];
[alertController addAction:actionAlbum];
[alertController addAction:actionCamera];
[self presentViewController:alertController animated:YES completion:nil];
转载于:https://www.cnblogs.com/onlyMyRailGun/p/5633594.html
本文详细介绍在iOS应用中如何使用UIAlertController弹窗提供用户选择从相册选取照片或使用相机拍照的功能。通过UIImagePickerController实现相册和相机源的判断与调用,并处理设备上可能存在的权限或硬件缺失情况。
2088

被折叠的 条评论
为什么被折叠?



