1. Controller Implementation Agent:
Uiactionsheetdelegate,uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate
2. Add a gesture to the picture:
UITapGestureRecognizer *gs=[[uitapgesturerecognizer alloc]initwithtarget:self Action: @selector (ChoicePic)];
[Picimageview Addgesturerecognizer:gs];
Picimageview.userinteractionenabled=yes;
3. How to implement gestures:
Uiactionsheet *sheet=[[uiactionsheet alloc]initwithtitle:sheet_pic_source_title delegate:self cancelButtonTitle: Sheet_pic_source_cacel Destructivebuttontitle:nil Otherbuttontitles:sheet_pic_source_camera,sheet_pic_source_ PHOTO, nil];
[Sheet ShowInView:self.view];
4. Implement sheet corresponding Agent method:
-(void) Actionsheet: (Uiactionsheet *) Actionsheet Clickedbuttonatindex: (Nsinteger) buttonindex{
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
picker.delegate=self;
if (buttonindex==0) {
if ([Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {
Picker.sourcetype = Uiimagepickercontrollersourcetypecamera;
}else{
[Utiltool Showalertview:alert_warn_title setmsg:open_camera_errormsg];
}
[Self Presentviewcontroller:picker animated:yes completion:nil];
}else if (buttonindex==1) {
Picker.sourcetype=uiimagepickercontrollersourcetypephotolibrary;
[Self Presentviewcontroller:picker animated:yes completion:nil];
}else{
}
}
5. Implement select photo or Camera Proxy method:
-(void) Imagepickercontroller: (Uiimagepickercontroller *) picker Didfinishpickingmediawithinfo: (nsdictionary *) info{
[uiapplication sharedapplication]. Statusbarhidden=no;
[Picker dismissviewcontrolleranimated:yes Completion:nil];
nsstring *mediatype=[info objectforkey: Uiimagepickercontrollermediatype];
if ([mediatype isequaltostring:@ "Public.image"]) {
UIImage *image=[info Objectforkey:uiimagepickercontrolleroriginalimage];
picimageview.image =image;
Objective: To determine whether a picture is selected, you can simply determine if you need to upload a picture
Ispic=1;
if (Picker.sourcetype = = Uiimagepickercontrollersourcetypecamera)
Uiimagewritetosavedphotosalbum (image, nil, nil, nil);
}
}
iOS Select picture