ifish/Ifish/controllers/IfishTabControllers/我的/mineControllers/InfoViewController.m

864 lines
31 KiB
Objective-C

//
// InfoViewController.m
// Ifish
//
// Created by imac on 15/10/8.
// Copyright © 2015年 imac. All rights reserved.
//
#import "InfoViewController.h"
#import "AFNetworking.h"
#import "MyMD5.h"
#import "UIImage+ImageEffects.h"
#import "UIImageView+WebCache.h"
//#import <RongIMKit/RongIMKit.h>
#import "InfoViewNiChengCell.h"
#import "InfoQianMingCell.h"
#import "InfoXingBieCell.h"
#define NICHENGCELL_TAG 12340
#define XINGBIECELL_TAG 12341
#define QIANMINGCELL_TAG 12342
#import "infoSureBtnCell.h"
#import "SVProgressHUD.h"
#import "UIView+Toast.h"
#import "IfishUserDefaultHelper.h"
@interface InfoViewController ()<UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,MBProgressHUDDelegate,UITextViewDelegate>
//@property(nonatomic,strong)UIBarButtonItem*rightItem;
@property (weak, nonatomic) IBOutlet UIButton *sureBUtton;
@property(nonatomic,strong) UserModel*usermodel;
@end
@implementation InfoViewController
- (void)viewDidLoad {
// [self enablestateNo];
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
[self creatUserImg];
[self creatUserImgback];
self.infoTab.delegate = self;
self.infoTab.dataSource = self;
self.infoTab.backgroundColor = COLOR_MIAN;
self.infoTab.separatorStyle= UITableViewCellSeparatorStyleNone;
self.headerView.userInteractionEnabled = YES;
[self.headerView addSubview:self.userImg];
self.infoTab.tableHeaderView = self.headerView;
self.usermodel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
self.navigationItem.title=@"我的信息";
self.view.backgroundColor = COLOR_MIAN;
[self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor whiteColor]}];
UITapGestureRecognizer*tapGestrueRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapgestrue)];
self.userImg.userInteractionEnabled=YES;
[self.userImg addGestureRecognizer:tapGestrueRecognizer];
UITapGestureRecognizer*tabGestrueRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tabViewGestrue)];
[self.infoTab addGestureRecognizer:tabGestrueRecognizer];
// self.rightItem=[[UIBarButtonItem alloc]initWithTitle:@"编辑" style:UIBarButtonItemStyleDone target:self action:@selector(editclick)];
// self.navigationItem.rightBarButtonItem=self.rightItem;
//[self showUI];
}
-(void)tabViewGestrue{
[self hiddenKeybord];
}
#pragma mark - tableView
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if (section == 0) {
return 3;
}else{
return 1;
}
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 2;
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section==0&&indexPath.row==0) {
InfoViewNiChengCell *nichengCell=[tableView dequeueReusableCellWithIdentifier:@"InfoViewNiChengCell"];
if (nichengCell==nil) {
nichengCell= [[[NSBundle mainBundle]loadNibNamed:@"InfoViewNiChengCell" owner:self options:nil]lastObject];
}
nichengCell.niChengField.delegate=self;
nichengCell.tag = NICHENGCELL_TAG;
[nichengCell loadNiChengwith:self.usermodel];
nichengCell.selectionStyle = UITableViewCellSelectionStyleNone;
return nichengCell;
}else if (indexPath.section==0&&indexPath.row==1){
InfoXingBieCell *xingBieCell=[tableView dequeueReusableCellWithIdentifier:@"InfoXingBieCell"];
if (xingBieCell==nil) {
xingBieCell= [[[NSBundle mainBundle]loadNibNamed:@"InfoXingBieCell" owner:self options:nil]lastObject];
}
xingBieCell.tag = XINGBIECELL_TAG;
[xingBieCell.InfoXingBieBtn addTarget:self action:@selector(xingbieClick) forControlEvents:UIControlEventTouchUpInside];
[xingBieCell loadXingBieWith:self.usermodel];
xingBieCell.selectionStyle = UITableViewCellSelectionStyleNone;
return xingBieCell;
}else if (indexPath.section==0&&indexPath.row==2){
InfoQianMingCell *qianMingCell=[tableView dequeueReusableCellWithIdentifier:@"InfoQianMingCell"];
if (qianMingCell==nil) {
qianMingCell= [[[NSBundle mainBundle]loadNibNamed:@"InfoQianMingCell" owner:self options:nil]lastObject];
}
qianMingCell.tag = QIANMINGCELL_TAG;
qianMingCell.infoQianMingView.delegate=self;
qianMingCell.infoQianMingView.returnKeyType = UIReturnKeyDefault;
qianMingCell.infoQianMingView.showsVerticalScrollIndicator = NO;
[qianMingCell loadQianmingWith:self.usermodel];
qianMingCell.selectionStyle = UITableViewCellSelectionStyleNone;
return qianMingCell;
}else if (indexPath.section==1&&indexPath.row==0){
infoSureBtnCell *btCell=[tableView dequeueReusableCellWithIdentifier:@"infoSureBtnCell"];
if (btCell==nil) {
btCell= [[[NSBundle mainBundle]loadNibNamed:@"infoSureBtnCell" owner:self options:nil]lastObject];
}
[btCell.infoSureBtn addTarget:self action:@selector(yesButton:) forControlEvents:UIControlEventTouchUpInside];
return btCell;
}
return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
if (section==1) {
return 20;
}else{
return 0;
}
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
if (indexPath.section == 0 && indexPath.row == 2) {
return 100;
}else{
return 50;
}
}
- (BOOL)textViewShouldBeginEditing:(UITextView *)textView{
InfoQianMingCell *qianMingCell =[self.infoTab viewWithTag:QIANMINGCELL_TAG];
if (textView ==qianMingCell.infoQianMingView){
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(qianmingkeyboradWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
return YES;
}
- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
// if ([text isEqualToString:@"\n"]) {
//
// [textView resignFirstResponder]; //[要实现的方法]
//
// return NO;
//
// }
// 键盘动画时间
// double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//视图下沉恢复原状
// [UIView animateWithDuration:duration animations:^{
// self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
// }];
return YES;
}
-(void)showUI{
self.sureBUtton.backgroundColor=COLOR_LABEL_TITLE;
self.sureBUtton.layer.masksToBounds = YES;
self.sureBUtton.layer.cornerRadius = 5;
}
-(UIView*)creatUserImgback{
if (! self.headerView) {
self.headerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenSize.width,140)];
self.headerView.layer.masksToBounds = YES;
self.headerView.layer.cornerRadius = 50;
}
return self.headerView;
}
-(UIImageView*)creatUserImg{
if (! self.userImg) {
self.userImg = [[UIImageView alloc] initWithFrame:CGRectMake(kScreenSize.width/2 - 50, 20, 100,100)];
self.userImg.layer.masksToBounds = YES;
self.userImg.layer.cornerRadius = 50;
}
return self.userImg;
}
-(void)initImageView{
//self.backImg =[[UIImageView alloc] initWithFrame:CGRectMake(0, 0, kScreenSize.width,140)];
UserModel*umodel=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
if ([umodel.userImg isKindOfClass:[NSNull class]]) {
//int i = (arc4random()%7) + 1;// 设置随机头像
//int i = 1;
// [self.backImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]];
[self.userImg setImage:[UIImage imageNamed:@"account"]];
}else if ([umodel.userImg isEqualToString:@""]){
// int i = (arc4random()%11) + 1;// 设置随机头像
// [self.backImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"acount%d.png",i]]];
//int i = (arc4random()%7) + 1;// 设置随机头像
int i = 1;
// [self.backImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]];
//[self.backImg setImage:[UIImage imageNamed:@"account"]];
[self.userImg setImage:[UIImage imageNamed:[NSString stringWithFormat:@"userIcon%d.png",i]]];
}else{
// [self.backImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]] placeholderImage:[UIImage imageNamed:@""]];
NSLog(@"%@",[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]);
[self.userImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetIconUrl,umodel.userImg]] placeholderImage:[UIImage imageNamed:@""] options:SDWebImageAllowInvalidSSLCertificates];
}
// [self createEfectbackImag];
}
-(void)viewWillAppear:(BOOL)animated{
self.navigationController.navigationBarHidden=NO;
dispatch_async(dispatch_get_main_queue(), ^{
[self initImageView];
});
_HUD=[MBProgressHUD showHUDAddedTo:self.view animated:YES];
_HUD.delegate=self;
[_HUD hide:YES afterDelay:0.5];
}
-(void)viewDidDisappear:(BOOL)animated{
self.navigationController.navigationBarHidden=NO;
}
-(void)createEfectbackImag{
// [self.backImg setImage:[self.userImg.image applyBlurWithRadius:28 tintColor:[UIColor colorWithWhite:2 alpha:0.5] saturationDeltaFactor:3.0 maskImage:nil]];
}
-(void)editclick{
// EditViewController*deitVC=[[EditViewController alloc]init];
// [self.navigationController pushViewController:deitVC animated:YES];
// [self enableStateYes];
// self.navigationItem.rightBarButtonItem=nil;
}
-(void)enablestateNo{
// self.nianling.enabled=NO;
// self.xingbiebutton.enabled=NO;
//self.nicheng.enabled=NO;
self.sureBUtton.enabled=NO;
}
-(void)enableStateYes{
self.sureBUtton.enabled=YES;
// self.nicheng.enabled=YES;
//self.xingbiebutton.enabled=YES;
//self.nianling.enabled=YES;
//self.nianling.textColor=[UIColor redColor];
// [self.xingbiebutton setTitleColor:[UIColor redColor] forState:UIControlStateNormal];
//self.nicheng.textColor=[UIColor redColor];
}
-(void)Sureclick{
UserModel*model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
InfoXingBieCell *xingBieCell=[self.infoTab viewWithTag:XINGBIECELL_TAG];
InfoQianMingCell *qianMingCell =[self.infoTab viewWithTag:QIANMINGCELL_TAG];
if ([xingBieCell.InfoXingBieBtn.titleLabel.text isEqualToString:@""]) {
model.userSex=@"";
}else if ([xingBieCell.InfoXingBieBtn.titleLabel.text isEqualToString:@""]){
model.userSex=@"1";
}else if ([xingBieCell.InfoXingBieBtn.titleLabel.text isEqualToString:@""]){
model.userSex=@"0";
};
InfoViewNiChengCell *nichengcell=[self.infoTab viewWithTag:NICHENGCELL_TAG];
if (nichengcell.niChengField.text.length ==0) {
[self.view makeToast:@"用户名不能为空"];
return;
}
int nameLength = [self convertToInt:nichengcell.niChengField.text];
if (nameLength>=10) {
[self.view makeToast:@"用户名小于十个字"];
return;
}
if (![self isIncludeSpecialCharact:nichengcell.niChengField.text]) {
if (![model.nickName isEqualToString:nichengcell.niChengField.text]) {
//
[self gaiMingJiaJinBi];
}
model.signature=qianMingCell.infoQianMingView.text;
model.nickName=nichengcell.niChengField.text;
[dataContorl resetUser:model];
[AFHttpTool updateUserWithUserId:model.userId nickName:model.nickName phoneNumber:@"" userSex:model.userSex userImg:@"" signature:model.signature timestamp:0 token:@"" success:^(id response) {
if (response) {
NSDictionary *reDic=[NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:nil];
if ([reDic[@"result"] isEqualToString:@"100"]) {
[self.view makeToast:@"修改成功"];
}else if ([reDic[@"result"] isEqualToString:@"101"]){
[self.view makeToast:@"失败"];
}else if ([reDic[@"result"] isEqualToString:@"211"]){
[self.view makeToast:@"用户ID不存在"];
}else if ([reDic[@"result"] isEqualToString:@"213"]){
[self.view makeToast:@"包含敏感词[官方,爱鱼奇]"];
}
}
} failure:^(NSError *err) {
[self.view makeToast:@"请求信息失败"];
}];
}else{
[self showTitle:@"提醒" messsage:@"昵称只能包含中文、中英文字母、数字和下划线"];
}
}
//判断是否包含特殊字符串 即非数字字母下划线
-(BOOL)isIncludeSpecialCharact:(NSString *)str {
NSString *regex =@"(^[a-zA-Z0-9_\u4e00-\u9fa5]+$)";
NSPredicate * pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
BOOL isRight = ![pred evaluateWithObject:str];
return isRight;
}
//统计含中英文混编的NSString 字符串长度
- (int)convertToInt:(NSString *)strtemp {
int strlength = 0;
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
if (*p) {
p++;
strlength++;
}
else {
p++;
}
}
return (strlength+1)/2;
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
-(void)tapgestrue{
if (IFISHIOS8) {
UIAlertController*alertCT=[UIAlertController alertControllerWithTitle:@"获取图片" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
// 判断是否支持相机 模拟器无相机
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
UIAlertAction*action=[UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
// 相机
UIImagePickerController *imagePicker=[[UIImagePickerController alloc]init];
imagePicker.delegate=self;
imagePicker.allowsEditing=YES;
imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
[self presentViewController:imagePicker animated:YES completion:nil];
}];
[alertCT addAction:action];
}
UIAlertAction*action1=[UIAlertAction actionWithTitle:@"从相册选取" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
//相册
UIImagePickerController*imgpic=[[UIImagePickerController alloc]init];
imgpic.delegate=self;
imgpic.allowsEditing=YES;
imgpic.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:imgpic animated:YES completion:nil];
}];
[alertCT addAction:action1];
UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
}];
[alertCT addAction:cancelAction];
[self presentViewController:alertCT animated:YES completion:nil];
}else{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.photosheet=[[UIActionSheet alloc]initWithTitle:@"获取图片" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照",@"从相册选择", nil];
}
[self.photosheet showInView:self.view];
}
}
#pragma mark--UIActionSheetDelegate IOS7
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (actionSheet==self.photosheet) {
if (buttonIndex==actionSheet.cancelButtonIndex) {
return;
}
NSUInteger sourceType=0;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
switch (buttonIndex) {
case 0:
{
sourceType=UIImagePickerControllerSourceTypeCamera;
NSLog(@"1");
}
break;
case 1:
{
sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
NSLog(@"2");
}
break;
default:
break;
}
}else{
if (buttonIndex==1) {
sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
}
// 转跳页面
UIImagePickerController*imgPic=[[UIImagePickerController alloc]init];
imgPic.delegate=self;
imgPic.allowsEditing=YES;
imgPic.sourceType=sourceType;
[self presentViewController:imgPic animated:YES completion:nil];
}else if (actionSheet==self.sexsheet){
InfoXingBieCell *xingBieCell=[self.infoTab viewWithTag:XINGBIECELL_TAG];
if (buttonIndex==0) {
[xingBieCell.InfoXingBieBtn setTitle:@"" forState:UIControlStateNormal];
}else if (buttonIndex ==1){
[xingBieCell.InfoXingBieBtn setTitle:@"" forState:UIControlStateNormal];;
}
}
}
#pragma mark-- 保存至沙河
-(void)saveImage:(UIImage*)currentImage withName:(NSString*)imageName{
//UIImage *smallImage=[self scaleFromImage:currentImage toSize:CGSizeMake(80.0f, 80.0f)];
UIImage *smallImage = [self thumbnailWithImageWithoutScale:currentImage size:CGSizeMake(300.0f, 300.0f)];
NSData*imageData=UIImageJPEGRepresentation(smallImage,1.0f);// 1 不缩放保存
// CGFloat length = [imageData length]/1024;
// 获取沙河目录
NSString *fullPath=[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:imageName];
[imageData writeToFile:fullPath atomically:YES];
}
// 改变图像的尺寸,方便上传服务器
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
//保持原来的长宽比,生成一个缩略图
- (UIImage *)thumbnailWithImageWithoutScale:(UIImage *)image size:(CGSize)asize
{
UIImage *newimage;
if (nil == image) {
newimage = nil;
}
else{
CGSize oldsize = image.size;
CGRect rect;
if (asize.width/asize.height > oldsize.width/oldsize.height) {
rect.size.width = asize.width*oldsize.height/oldsize.width;
// rect.size.height = asize.height*oldsize.height/oldsize.width;
rect.size.height = asize.width*oldsize.height/oldsize.width;
rect.origin.x = (asize.width - rect.size.width)/2;
rect.origin.y = 0;
}
else{
//rect.size.width = asize.width;
rect.size.width = asize.height*oldsize.width/oldsize.height;
rect.size.height = asize.height*oldsize.width/oldsize.height;
rect.origin.x = 0;
rect.origin.y = (asize.height - rect.size.height)/2;
}
UIGraphicsBeginImageContext(asize);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [[UIColor clearColor] CGColor]);
UIRectFill(CGRectMake(0, 0, asize.width, asize.height));//clear background
[image drawInRect:rect];
newimage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
}
return newimage;
}
#pragma mark --选取完成后调用方法
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info{
[picker dismissViewControllerAnimated:YES completion:nil]
;
UIImage*img=[info objectForKey:UIImagePickerControllerEditedImage];
[self saveImage:img withName:@"avatar.png"];
NSString*fullpath=[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"avatar.png"];
UIImage*saveImage=[[UIImage alloc]initWithContentsOfFile:fullpath];
self.fullpath=fullpath;
//  设置展示图片
self.userImg.image=saveImage;
// 上传
self.saveImage=saveImage;
NSString*url=kSafeUploadFile;
[self postImageWithUrl:url];
}
#pragma mark-上传头像
-(void)postImageWithUrl:(NSString*)url{
AFHTTPRequestOperationManager*manager=[AFHTTPRequestOperationManager manager];
//manager.requestSerializer = [AFJSONRequestSerializer serializer];
[manager.requestSerializer setValue:[NSString stringWithFormat:@"5fc7bdada110e3a6eefd3065b8d8d995"] forHTTPHeaderField:@"appKey"];
NSString *nonceStr=[dataContorl get10LengthString];
[manager.requestSerializer setValue:nonceStr forHTTPHeaderField:@"nonce"];
NSString *curTimeString = [dataContorl getCurrentSyatemTime];
[manager.requestSerializer setValue:curTimeString forHTTPHeaderField:@"curTime"];
NSString *normalCheckSum = [NSString stringWithFormat:@"%@%@%@",IFISHAPPSECRET,nonceStr,curTimeString];
NSString *md5CheckSum = [MyMD5 md5:normalCheckSum];
[manager.requestSerializer setValue:md5CheckSum forHTTPHeaderField:@"checkSum"];
manager.responseSerializer=[AFHTTPResponseSerializer serializer];
// manager.responseSerializer.acceptableContentTypes=[NSSet setWithObject:@"text/html"];
NSMutableDictionary * para = [NSMutableDictionary dictionary];
UserModel *model=[[DataCenter defaultDtacenter]valueForKey:@"UserLogIn"];
[para setValue:model.userId forKey:@"userId"];
[para setValue:@"png" forKey:@"fileUpload"];// 图片类型 GIF,PNG,BMP,JPG,JPEG
[manager POST:url parameters:para constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
//上传时使用当前的系统事件作为文件名
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
formatter.dateFormat = @"yyyyMMddHHmmss";
NSString *str = [formatter stringFromDate:[NSDate date]];
NSString *fileName = [NSString stringWithFormat:@"%@.jpg", str];
//服务器上传文件的字段和类型
NSData*data=UIImageJPEGRepresentation(self.saveImage,0.05f);
[formData appendPartWithFileData:data name:@"fileUpload" fileName:fileName mimeType:@"image/jpeg"];
[formData appendPartWithFormData:data name:@"avatar.png"];
} success:^(AFHTTPRequestOperation *operation, id responseObject) {
NSDictionary*resultDic=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
NSLog(@"result:%@",resultDic[@"result"]);
NSDictionary*dataDic=resultDic[@"data"];
if ([resultDic[@"result"] isEqualToString:@"100"]) {
NSLog(@"data:%@",resultDic[@"data"]);
// 刷新UI
dispatch_async(dispatch_get_main_queue(), ^{
model.userImg=dataDic[@"userImg"];
// [self createEfectbackImag];
NSLog(@"%@",[NSString stringWithFormat:@"%@%@",kGetIconUrl,model.userImg]);
[self.userImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",kGetIconUrl,model.userImg]] placeholderImage:[UIImage imageNamed:@"camer.png"]options:SDWebImageAllowInvalidSSLCertificates];
NSString*fullpath=[[NSHomeDirectory() stringByAppendingPathComponent:@"Documents"]stringByAppendingPathComponent:@"avatar.png"];
UIImage*saveImage=[[UIImage alloc]initWithContentsOfFile:fullpath];
[self.backImg setImage:[saveImage applyBlurWithRadius:28 tintColor:[UIColor colorWithWhite:2 alpha:0.5] saturationDeltaFactor:3.0 maskImage:nil]];
});
//改头像加金币
[self changeUserIcon];
}else if ([resultDic[@"result"] isEqualToString:@"101"]){
[self.view makeToast:@"上传失败"];
}else if ([resultDic[@"result"] isEqualToString:@"205"]){
[self.view makeToast:@"图片格式不正确"];
}else if ([resultDic[@"result"] isEqualToString:@"206"]){
[self.view makeToast:@"请求被舍弃,未执行"];
}else if ([resultDic[@"result"] isEqualToString:@"211"]){
[self.view makeToast:@"用户ID不存在"];
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
[self.view makeToast:@"网络异常"];
}];
}
#pragma mark--按取消按钮调用方法
-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)yesButton:(UIButton *)sender {
[self Sureclick];
}
#pragma mark-处理收键盘
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[textField resignFirstResponder];
return YES;
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
[self hiddenKeybord];
}
-(void)hiddenKeybord{
InfoQianMingCell *qianMingCell =[self.infoTab viewWithTag:QIANMINGCELL_TAG];
InfoViewNiChengCell *nichengcell=[self.infoTab viewWithTag:NICHENGCELL_TAG];
[nichengcell.niChengField resignFirstResponder];
[qianMingCell.infoQianMingView resignFirstResponder];
}
-(void)xingbieClick{
[self.view endEditing:YES];
[self creatActionSheet];
}
-(void)creatActionSheet{
self.sexsheet=[[UIActionSheet alloc]initWithTitle:@"性别选择" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"",@"" ,nil];
[self.sexsheet showInView:self.view];
}
// 处理键盘
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
InfoViewNiChengCell *nichengcell=[self.infoTab viewWithTag:NICHENGCELL_TAG];
if (textField==nichengcell.niChengField) {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(nichengkeyboradWillShow:) name:UIKeyboardWillShowNotification object:nil];
}
// else if (textField==_nianling){
//
// [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(qianmingkeyboradWillShow:) name:UIKeyboardWillShowNotification object:nil];
// }
return YES;
}
- (void) nichengkeyboradWillShow:(NSNotification *)notification{
CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
//计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
InfoViewNiChengCell *nichengcell=[self.infoTab viewWithTag:NICHENGCELL_TAG];
CGFloat offset = (nichengcell.niChengField.frame.origin.y+nichengcell.niChengField.frame.size.height+INTERVAL_KEYBOARD) - (self.view.frame.size.height - kbHeight);
// 取得键盘的动画时间,这样可以在视图上移的时候更连贯
double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//将视图上移计算好的偏移
if(offset > 0) {
[UIView animateWithDuration:duration animations:^{
self.view.frame = CGRectMake(0.0f, -offset, self.view.frame.size.width, self.view.frame.size.height);
}];
}
}
-(void)qianmingkeyboradWillShow:(NSNotification *)notification{
InfoQianMingCell *qianMingCell =[self.infoTab viewWithTag:QIANMINGCELL_TAG];
CGFloat kbHeight = [[notification.userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
// CGRect keyboardFrame = [notification.userInfo[UIKeyboardFrameEndUserInfoKey] CGRectValue];
//计算出键盘顶端到inputTextView panel底端的距离(加上自定义的缓冲距离INTERVAL_KEYBOARD)
CGRect QianMingViewRect = [qianMingCell.infoQianMingView convertRect:qianMingCell.infoQianMingView.bounds toView:self.view];
CGFloat offset = (QianMingViewRect.origin.y+QianMingViewRect.size.height+INTERVAL_KEYBOARD) - (self.infoTab.frame.size.height - kbHeight);
// 取得键盘的动画时间,这样可以在视图上移的时候更连贯
double duration = [[notification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//CGRect QianMingViewRect = [qianMingCell.infoQianMingView convertRect:qianMingCell.infoQianMingView.bounds toView:self.view];
// CGFloat QianMingViewMargin =(QianMingViewRect.origin.y + QianMingViewRect.size.height + 10);
//CGFloat transformY = keyboardFrame.origin.y - QianMingViewMargin;
//将视图上移计算好的偏移
if(offset > 0) {
[UIView animateWithDuration:duration animations:^{
self.view.frame = CGRectMake(0.0f, -offset , self.view.frame.size.width, self.view.frame.size.height);
// if (keyboardFrame.origin.y < self.view.frame.size.height) {
// self.view.transform = CGAffineTransformMakeTranslation(0,transformY);
// }else{
// self.view.transform = CGAffineTransformMakeTranslation(0, 0);
// }
}];
}
}
//恢复原始视图位置
/////键盘消失事件
- (void)keyboardWillHide:(NSNotification *)notify {
// 键盘动画时间
double duration = [[notify.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] doubleValue];
//视图下沉恢复原状
[UIView animateWithDuration:duration animations:^{
self.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
}];
}
//-(void)refreshRongYunUserInfo:(RCUserInfo*)userInfo WithUserId:(NSString*)userId{
//
// [[RCIM sharedRCIM] refreshUserInfoCache:userInfo withUserId:userId];
//
//}
#pragma mark -改名字加金币
-(void)gaiMingJiaJinBi{
//修改用户名字 加金币
[[IfishUserObsever sharedInstance] addGoldWith:RENAME addType:IFISHADDGOLDTYPE1];
}
#pragma mark -改头像加金币
-(void)changeUserIcon{
//改头像加金币 加金币
[[IfishUserObsever sharedInstance] addGoldWith:OPLOADHEADIMG addType:IFISHADDGOLDTYPE1];
}
@end