- (IBAction)photo:(id)sender {
UIImagePickerController* imagePickerController = [[UIImagePickerControlleralloc]init];
imagePickerController.navigationBar.tintColor= [UIColorblackColor];
imagePickerController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
imagePickerController.delegate=self;
imagePickerController.allowsEditing=YES;
[selfpresentViewController:imagePickerControlleranimated:YEScompletion:nil];
}
- (IBAction)picture:(id)sender {
if(![UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIAlertController*alertController=[UIAlertControlleralertControllerWithTitle:nilmessage:@"该设备不支持拍照功能"preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction*cancelAction = [UIAlertActionactionWithTitle:@"取消"style:UIAlertActionStyleCancelhandler:nil];
//initWithTitle:nil
// message:@"该设备不支持拍照功能"
// delegate:nil
// cancelButtonTitle:nil
// otherButtonTitles:@"好", nil];
[alertControlleraddAction:cancelAction];
[selfpresentViewController:alertControlleranimated:YEScompletion:nil];
}
else
{
UIImagePickerController* imagePickerController = [[UIImagePickerControlleralloc]init];
imagePickerController.sourceType=UIImagePickerControllerSourceTypeCamera;
imagePickerController.delegate=self;
imagePickerController.allowsEditing=NO;
[selfpresentViewController:imagePickerControlleranimated:YEScompletion:nil];
}
}
#pragma mark --UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingImage:(UIImage*)image editingInfo:(NSDictionary*)editingInfo {
_myImageView.image=image;
NSLog(@"%s",__func__);
[pickerdismissViewControllerAnimated:YEScompletion:nil];
UITapGestureRecognizer*tap=[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(singleTap:)];
tap.numberOfTapsRequired=1;
[_myImageViewaddGestureRecognizer:tap];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker {
NSLog(@"%s",__func__);
[pickerdismissViewControllerAnimated:YEScompletion:nil];
}
网友评论