iOS Latest call Phone album select Avatar (Uiactionsheet expired)

Source: Internet
Author: User

Because

Uiactionsheet expired so you can use mobile albums like downgrade

Premise do not forget to add the following two agents

Uiimagepickercontrollerdelegate,uinavigationcontrollerdelegate

Also need to go to the plist file to add Camera album permissions or to Crash yo

Change your avatar

-(Ibaction) Changeheadim: (ID) Sender {

Create a Uiimagepickercontroller object and set the proxy and editable

Uiimagepickercontroller * Imagepicker = [[Uiimagepickercontroller alloc] init];

imagepicker.editing = YES;

Imagepicker.delegate = self;

imagepicker.allowsediting = YES;

Create a sheet prompt to select a camera or album

Uialertcontroller * alert = [Uialertcontroller alertcontrollerwithtitle:@ "Please select open mode" Message:nil Preferredstyle: Uialertcontrollerstyleactionsheet];

Camera options

Uialertaction * camera = [uialertaction actionwithtitle:@ "Camera" Style:uialertactionstyledefault handler:^ (UIAlertAction * _nonnull action) {

Set Uiimagepickercontroller Object-related properties when selecting a camera

Imagepicker.sourcetype = Uiimagepickercontrollersourcetypecamera;

Imagepicker.modalpresentationstyle = Uimodalpresentationfullscreen;

Imagepicker.cameracapturemode = Uiimagepickercontrollercameracapturemodephoto;

Jump to Uiimagepickercontroller controller pop-up camera

[Self Presentviewcontroller:imagepicker animated:yes completion:nil];

}];

Album Options

uialertaction * photo = [Uialertaction actionwithtitle:@ "album" Style:uialertactionstyledefault handler:^ (UIAlertAction * _nonnull action) {

Set Uiimagepickercontroller Object-related properties when selecting albums

Imagepicker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;

Jump to Uiimagepickercontroller Controller pop-up album

[Self Presentviewcontroller:imagepicker animated:yes completion:nil];

}];

Cancel button

Uialertaction * Cancel = [uialertaction actionwithtitle:@ "Cancel" Style:uialertactionstylecancel handler:^ (UIAlertAction * _nonnull action) {

[Self dismissviewcontrolleranimated:yes completion:nil];

}];

Add Individual button Events

[Alert Addaction:camera];

[Alert Addaction:photo];

[Alert Addaction:cancel];

Pop-up sheet prompt box

[Self Presentviewcontroller:alert animated:yes completion:nil];

}

#pragma mark-image Picker Delegte

-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary *) info

{

[Picker Dismissviewcontrolleranimated:yes completion:^{}];

UIImage *image = [info objectforkey:uiimagepickercontrolleroriginalimage];

Original with Image.size.width/image.size.height

Compression

Uigraphicsbeginimagecontext (Cgsizemake (800, 600)); Size is the cgsize type, which is the size of the picture you need

[Image drawinrect:cgrectmake (0, 0, 800, 600)];

uiimage* scaledimage = Uigraphicsgetimagefromcurrentimagecontext ();

Uigraphicsendimagecontext ();

float scales = image.size.height/image.size.width;

UIImage *normalimg;

If you need to change the pressed size, adjust the scale instead of KK or AA

if (Image.size.width > | | image.size.height > 800) {//The 1000 here is scale, and everything changes

if (Scales > 1) {

Cgsize newSize = Cgsizemake (600/scales, 800);

Uigraphicsbeginimagecontext (newSize);

[Image drawinrect:cgrectmake (0, 0, Newsize.width, newsize.height)];

Normalimg = Uigraphicsgetimagefromcurrentimagecontext ();

}else {

Cgsize newSize = Cgsizemake (*, * scales);

Uigraphicsbeginimagecontext (newSize);

[Image Drawinrect:cgrectmake (0,0,newsize.width,newsize.height)];

Normalimg = Uigraphicsgetimagefromcurrentimagecontext ();

}

}else {

Normalimg=image;

}

NSData *data = uiimagepngrepresentation (normalimg);

Self.editHeadIM.image = normalimg;

}

-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker

{

[Self Dismissviewcontrolleranimated:yes completion:^{}];

}

iOS Latest call Phone album select Avatar (Uiactionsheet expired)

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.