调用系统的相机和相册

来源:互联网 发布:计算机机房网络维护ppt 编辑:程序博客网 时间:2024/05/17 07:28
    UIActionSheet *as = [[UIActionSheet alloc]initWithTitle:nil
                                                   delegate:self
                                          cancelButtonTitle:@"取消"
                                     destructiveButtonTitle:@"打开照相机"
                                          otherButtonTitles:@"从手机相册获取", nil
                         ];
    as.tag=1;

    [as showInView:self.view];


//actionSheet协议
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
    switch (buttonIndex) {
        case 0:{
            if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
                UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
                [ipc setSourceType:UIImagePickerControllerSourceTypeCamera];
                ipc.delegate = self;
                ipc.allowsEditing = YES;
                [self presentViewController:ipc animated:YES completion:nil];
            }else{
                NSLog(@"这设备没相机");
            }
        }
            break;
        case 1:{
            UIImagePickerController *ipc = [[UIImagePickerController alloc]init];
            [ipc setSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
            ipc.delegate = self;
            ipc.allowsEditing = YES;
            [self presentViewController:ipc animated:YES completion:nil];
        }
            break;
    }
    
}


//选择完成
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
    
    UIImage*image=[info objectForKey:@"UIImagePickerControllerEditedImage"];
    self.sendimg=[NSMutableArray arrayWithObjects:image, nil];
    
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}
//取消选择图片
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
    [self dismissViewControllerAnimated:YES completion:^{
    }];
}



0 0
原创粉丝点击