美文网首页
iOS 调用系统相册,系统相机

iOS 调用系统相册,系统相机

作者: 孟维学 | 来源:发表于2016-07-22 14:13 被阅读86次

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUIImageView*imageV;

@property(nonatomic,strong)UIActionSheet*sheet;

@property(nonatomic,strong)UIImagePickerController*picker;

@end

@implementationViewController

- (void)viewDidLoad {

[superviewDidLoad];

}

- (IBAction)buttonClick:(id)sender {

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

self.sheet=[[UIActionSheetalloc]initWithTitle:@"选择"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"相机",@"本地相册",nil];

[self.sheetshowInView:self.view];

}else

{

self.sheet=[[UIActionSheetalloc]initWithTitle:@"选择"delegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"本地相册",nil];

[self.sheetshowInView:self.view];

}

}

-(void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

if(buttonIndex==0) {

self.picker=[[UIImagePickerControlleralloc]init];

self.picker.delegate=self;

self.picker.allowsEditing=YES;

self.picker.sourceType=UIImagePickerControllerSourceTypeCamera;

[selfpresentViewController:self.pickeranimated:YEScompletion:nil];

}elseif(buttonIndex==1){

self.picker=[[UIImagePickerControlleralloc]init

];

self.picker.delegate=self;

self.picker.allowsEditing=YES;

self.picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

[selfpresentViewController:self.pickeranimated:YEScompletion:nil];

}

}

-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info

{

[selfdismissViewControllerAnimated:YEScompletion:nil];

self.imageV.image=[infoobjectForKey:UIImagePickerControllerOriginalImage];

}

- (void)didReceiveMemoryWarning {

[superdidReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

相关文章

网友评论

      本文标题:iOS 调用系统相册,系统相机

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