@interface ViewController ()<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
@property (weak, nonatomic)IBOutlet UIImageView *imageV;
@property(nonatomic,retain)UIImagePickerController *imageController;
@end
@implementation ViewController
- (void)viewDidLoad
{
[superviewDidLoad];
}
- (void)didReceiveMemoryWarning
{
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//调用摄像机
- (IBAction)onCameraBtnAction:(id)sender {
//判断是否支持摄像头
if ([UIImagePickerControllerisCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
_imageController=[[UIImagePickerControlleralloc]init];
_imageController.sourceType=UIImagePickerControllerSourceTypeCamera;
_imageController.delegate=self;
_imageController.allowsEditing=YES;
[selfpresentViewController:_imageControlleranimated:YEScompletion:nil];
}else{
UIAlertView *alerV=[[UIAlertViewalloc]initWithTitle:@"提示"message:@"您的设备不支持摄像功能" delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:nil,nil];
[alerV show];
}
}
//调用图库
- (IBAction)onPhotoLibraryBtnAction:(id)sender {
_imageController=[[UIImagePickerControlleralloc]init];
_imageController.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
_imageController.delegate=self;
_imageController.allowsEditing=YES;
[selfpresentViewController:_imageControlleranimated:YEScompletion:nil];
}
//代理方法 选择完后调用
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image=[info objectForKey:UIImagePickerControllerEditedImage];
self.imageV.image=image;
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
//取消选择完成后调用
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YEScompletion:nil];
}
调用系统相机与图库
最新推荐文章于 2021-05-25 17:28:38 发布