需要遵守的代理协议:UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate

@property (nonatomic, strong) UIActionSheet *avatarActionSheet;

第一步:点击头像cell需要做的事情

[self.avatarActionSheet showInView:self.view];

第二步:

#pragma mark - 点击头像

- (UIActionSheet *)avatarActionSheet

{

if (!_avatarActionSheet) {

_avatarActionSheet = [[UIActionSheet alloc] initWithTitle:NSLocalizedString(@"选择你的头像", @"") delegate:self cancelButtonTitle:NSLocalizedString(@"取消", @"") destructiveButtonTitle:nil otherButtonTitles:NSLocalizedString(@"相机", @""), NSLocalizedString(@"在图片库选择", @""), nil];

}

return _avatarActionSheet;

}

#pragma mark - 弹框代理方法

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

{

GYLog(@"%d" , buttonIndex);

if (buttonIndex == 2) return;// 取消

[self showImagePickerViewController:buttonIndex];

}

- (void)showImagePickerViewController:(NSInteger)pickerUserAvatarType

{

UIImagePickerControllerSourceType sourceType;

NSString *description = nil;

switch (pickerUserAvatarType) {

case 0:

sourceType = UIImagePickerControllerSourceTypeCamera;

description = NSLocalizedString(@"该设备不支持相机", @"");

break;

case 1:

sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

description = NSLocalizedString(@"该设备不支持图片库", @"");

break;

}

if (![UIImagePickerController isSourceTypeAvailable:sourceType]) {

[self initalizerAlertViewWithTitle:NSLocalizedString(@"警告", @"") description:description];

return;

}

UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];

imagePickerController.delegate = self;

imagePickerController.allowsEditing = YES;

imagePickerController.sourceType = sourceType;

imagePickerController.videoQuality = UIImagePickerControllerQualityTypeMedium;

[self presentViewController:imagePickerController animated:YES completion:NULL];

}

- (void)initalizerAlertViewWithTitle:(NSString *)title description:(NSString *)description

{

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:title message:description delegate:nil cancelButtonTitle:nil otherButtonTitles: NSLocalizedString(@"确定", @""), nil];

[alertView show];

}

- (void)showAvatarImage:(UITapGestureRecognizer *)tapGesture

{

GYLog(@"----------------------");

}

#pragma mark - 图片选择控制器的代理

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

{

UIImage *userAvatar = [info valueForKey:UIImagePickerControllerEditedImage];

[self.userIconView setImage:userAvatar];

[picker dismissViewControllerAnimated:YES completion:NULL];

// 1.创建请求管理对象

AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];

// 2.封装请求参数

NSMutableDictionary *params = [NSMutableDictionary dictionary];

params[@"verify"] = [GYUserDefaults objectForKey:@"verify"];

params[@"avatar"] = userAvatar;

// 3.发送请求

NSString *str = [NSString stringWithFormat:@"http://%@/?action=personal&option=update_avatar",GYAPP_URL];

[mgr POST:str parameters:params constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { // 在发送请求之前调用这个block

NSData *data = UIImageJPEGRepresentation(userAvatar, 0.000001);

[formData appendPartWithFileData:data name:@"pic" fileName:@"" mimeType:@"image/jpeg"];

} success:^(AFHTTPRequestOperation *operation, id responseObject) {

[MBProgressHUD showSuccess:@"发送成功"];

#warning 是否需要进行数据存储

[GYUserDefaults setObject:responseObject[@"avatar"] forKey:@"avatar"];

} failure:^(AFHTTPRequestOperation *operation, NSError *error) {

[MBProgressHUD showError:@"发送失败"];

}];

}

ios 开发选取头像,图片库,相机,裁取图片的更多相关文章

  1. iOS 开发遇到 调不起相机问题

    在iOS 开发中 使用html 中的input 标签调起工程里面的相机,手机无反应 1.先看看info.plist 加没加相机的权限,添加Privacy - Camera Usage Descript ...

  2. iOS开发之表视图爱上CoreData

    在接触到CoreData时,感觉就是苹果封装的一个ORM.CoreData负责在Model的实体和sqllite建立关联,数据模型的实体类就相当于Java中的JavaBean, 而CoreData的功 ...

  3. iOS:iOS开发非常全的三方库、插件等等

    iOS开发非常全的三方库.插件等等 github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自git ...

  4. iOS开发之资料收集

    github排名:https://github.com/trending, github搜索:https://github.com/search. 此文章转自github:https://github ...

  5. iOS开发 非常全的三方库、插件、大牛博客等等

    UI 下拉刷新 EGOTableViewPullRefresh- 最早的下拉刷新控件. SVPullToRefresh- 下拉刷新控件. MJRefresh- 仅需一行代码就可以为UITableVie ...

  6. iOS开发系列--通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开发汇总

    --系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...

  7. iOS开发系列--并行开发其实很容易

    --多线程开发 概览 大家都知道,在开发过程中应该尽可能减少用户等待时间,让程序尽可能快的完成运算.可是无论是哪种语言开发的程序最终往往转换成汇编语言进而解释成机器码来执行.但是机器码是按顺序执行的, ...

  8. iOS - 开发类库

    开发类库   UI 项目名称 项目信息 1.MJRefresh 仅需一行代码就可以为UITableView或者CollectionView加上下拉刷新或者上拉刷新功能.可以自定义上下拉刷新的文字说明. ...

  9. iOS开发系列通讯录、蓝牙、内购、GameCenter、iCloud、Passbook系统服务开

    --系统应用与系统服务 iOS开发过程中有时候难免会使用iOS内置的一些应用软件和服务,例如QQ通讯录.微信电话本会使用iOS的通讯录,一些第三方软件会在应用内发送短信等.今天将和大家一起学习如何使用 ...

随机推荐

  1. MyEclipse启动和运行速度优化

    1:去除不需要加载的模块 Windows – Preferences - General - Startup and Shutdown,这个时候在右侧就显示出了Eclipse启动时加载的模块,可以根据 ...

  2. 时钟周期、振荡周期、机器周期、CPU周期、状态周期、指令周期、总线周期、任务周期

    http://blog.csdn.net/yangtalent1206/article/details/5853017 计算机系统有一系列的“周期”概念,区别.联系地理解这些概念至关重要.以下对时钟周 ...

  3. Classifying plankton with deep neural networks

    Classifying plankton with deep neural networks The National Data Science Bowl, a data science compet ...

  4. HDU 1176 免费馅饼(DP)

    点我看题目 题意 : 中文题.在直线上接馅饼,能接的最多是多少. 思路 :这个题其实以前做过.....你将这个接馅饼看成一个矩阵,也不能说是一个矩阵,反正就是一个行列俱全的形状,然后秒当行,坐标当列, ...

  5. DJANGO模板的BLOCK自定义技巧

    除了INCLUDE, EXTENDS基本的继承模板之外,如果想在本模板上,直接生成让同类页面继承的模板, 则可以需要自定义的地方实现自定义BLOCK, 先在本页面实现自己的BLOCK,然后,在继承的页 ...

  6. Error -27791: Server xx has shut down the connection prematurely

    最近在进行一次性能测试中遇到一个问题,并发较大的时候会出现LR出现Error -27791: Server xx has shut down the connection prematurely的ER ...

  7. [dp]POJ2559 && HDOJ1506 Largest Rectangle in a Histogram

    题意 给n个条形的高度, 问能放的最大矩形面积 分析: 从左到右 从右到左 各搞一遍 分别记录      L[i]记录列(从前往后)标 第几列开始 可以往后放高度为a[i]的矩形  R[i]记录列(从 ...

  8. 弱安全协议探测工具-sslciphercheck

    SSL(Secure Sockets Layer 安全套接层),及其继任者传输层安全(Transport Layer Security,TLS)是为 网络通信提供安全及数据完整性的一种安全协议.TLS ...

  9. ipconfig命令

    C:\Windows\System32>ipconfig -all Windows IP 配置 主机名 . . . . . . . . . . . . . : LuJunTao 主 DNS 后缀 ...

  10. IPv6 tutorial 3 New features: IPsec and LAN features

    https://4sysops.com/archives/ipv6-tutorial-part-3-new-features-ipsec-and-lan-features/ In the last p ...