#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIImageView*imageV;
@property(nonatomic,strong)UIActionSheet*sheet;
@property(nonatomic,strong)UIImagePickerController*picker;
@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.
网友评论