美文网首页
调取系统相册 照相机

调取系统相册 照相机

作者: 刘振杰 | 来源:发表于2016-08-18 11:12 被阅读27次

    - (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];

    }

    相关文章

      网友评论

          本文标题:调取系统相册 照相机

          本文链接:https://www.haomeiwen.com/subject/zyjvsttx.html