iOS Select picture

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.