UIAlertController *alertCtrl = [UIAlertController alertControllerWithTitle:@"提示" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *cancle = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action) {
//取消...
//删除图片
_sendImg = nil;
[sendImgView removeFromSuperview];
sendImgView = nil;
for (int i = 0; i < 4; i++) {
UIButton *btn = (UIButton *)[_editorBar viewWithTag:10 + i];
btn.transform = CGAffineTransformIdentity;
}
}];
UIAlertAction *photo = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//拍照...
//判断是否有摄像头
BOOL isCamera = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
if (!isCamera) {
//提示用户没有摄像头
UIAlertController *alertCtrl = [UIAlertController alertControllerWithTitle:@"提示" message:@"没有摄像头" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDestructive handler:nil];
[alertCtrl addAction:action];
[self presentViewController:alertCtrl animated:YES completion:nil];
return;
}
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
//图像来源于相机
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
}];
UIAlertAction *xiangce = [UIAlertAction actionWithTitle:@"相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
//相册
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
//图像来源于相册
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imagePicker animated:YES completion:nil];
}];
[alertCtrl addAction:photo];
[alertCtrl addAction:xiangce];
[alertCtrl addAction:cancle];
[self presentViewController:alertCtrl animated:YES complet