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)