iOSimagePicker使用方法,方便使用!三步轻松搞定!

王朝学院·作者佚名  2016-08-27
窄屏简体版  字體: 小  |  中  |  大  |  超大  

自己总结的修改头像的方法,只为方便自己查询使用!转发

步骤:1、遵守代理协议

<UIImagePickerControllerDelegate,UINavigationControllerDelegate,UIActionSheetDelegate>

2、点击事件{

UIActionSheet*choosePhotoActionSheet;

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

choosePhotoActionSheet = [[UIActionSheetalloc]initWithTitle:NSLocalizedString(@"选取图片",@"")

delegate:self

cancelButtonTitle:NSLocalizedString(@"取消",@"")

destructiveButtonTitle:nil

otherButtonTitles:NSLocalizedString(@"相机",@""),NSLocalizedString(@"相册",@""),nil];

}else{

choosePhotoActionSheet = [[UIActionSheetalloc]initWithTitle:NSLocalizedString(@"选取图片",@"")

delegate:self

cancelButtonTitle:NSLocalizedString(@"取消",@"")

destructiveButtonTitle

:nil

otherButtonTitles:NSLocalizedString(@"相册",@""),nil];

}

[choosePhotoActionSheetshowInView:self.view];

}

3、实现代理方法

#PRagma mark - UIActionSheetDelegate

- (void)actionSheet:(UIActionSheet*)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

NSUIntegersourceType =0;

if([UIImagePickerControllerisSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

switch(buttonIndex) {

case0:

sourceType =UIImagePickerControllerSourceTypeCamera;

break;

case1:

sourceType =UIImagePickerControllerSourceTypePhotoLibrary;

break;

case2:

return;

}

}else{

if(buttonIndex ==1) {

return;

}else{

sourceType =UIImagePickerControllerSourceTypeSavedPhotosAlbum;

}

}

UIImagePickerController*imagePickerController = [[UIImagePickerControlleralloc]init];

imagePickerController.delegate=self;

imagePickerController.allowsEditing=YES;

imagePickerController.sourceType= sourceType;

[selfpresentViewController:imagePickerControlleranimated:YEScompletion:^{

}];

}

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info

{

[selfdismissViewControllerAnimated:YEScompletion:^{

}];

self.tmpHeaderImg= [infoobjectForKey:UIImagePickerControllerEditedImage];

[self.imageViewUserHeadsetImage:self.tmpHeaderImg];

[selfuploadImage];

}

- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker

{

[selfdismissViewControllerAnimated:YEScompletion:^{

}];

}

 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
© 2005- 王朝網路 版權所有 導航