目标类需要确认的协议
@interface AddViewController : UIViewController<UINavigationControllerDelegate,UIImagePickerControllerDelegate>
1. //给头像图片添加一个处理事件
UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(dddd)];
self.myiamge.userInteractionEnabled = YES;
[self.myiamge addGestureRecognizer:tap];
2,//点击头像图片的处理方法
-(void)dddd
{
//弹出系统提供的相册,UIimagepickerviewcontroller
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController * picker = [[UIImagePickerController alloc ]init];
picker.delegate= self;
//指定源为相册
picker .sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:nil];
}
}
3,//代理方法,当点击相册中的某张图片时调用
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
//获取图片,从字典中
self.myiamge.image = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:nil];
}