123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- //
- // MyUserIconVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/2/26.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "MyUserIconVC.h"
- #import "LYLPhotoTailoringTool.h"
- @interface MyUserIconVC ()
- @property (weak, nonatomic) IBOutlet UIImageView *iconView;
- @property (weak, nonatomic) IBOutlet UIButton *moreBtn;
- @end
- @implementation MyUserIconVC
- +(MyUserIconVC *)initMyUserIconVC{
- MyUserIconVC *controller = [StoryboardManager.shared.myCenter instantiateViewControllerWithIdentifier:@"MyUserIconVC"];
- return controller;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- self.view.backgroundColor = UIColorHex(0x000000);
-
- if (self.HistoryVC) {
- NSString * urlString = [AppUserModel sharedAppUserModel].HistoryAvatarUrl;
- NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@"_50_50" withString:@""];
- [self.iconView sd_setImageWithURL:[NSURL URLWithString:strUrl]];
- }else{
- NSString * urlString = [AppUserModel sharedAppUserModel].AvatarUrl;
- NSString *strUrl = [urlString stringByReplacingOccurrencesOfString:@"_50_50" withString:@""];
- [self.iconView sd_setImageWithURL:[NSURL URLWithString:strUrl]];
- }
- WS(weakSelf);
- [self.moreBtn setAction:^{
- if (weakSelf.HistoryVC) {
- UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"保存图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf savePhoto];
-
- }];
- UIAlertAction *action5 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"取消");
- }];
- [action4 setValue:k6 forKey:@"_titleTextColor"];
- [action5 setValue:k6 forKey:@"_titleTextColor"];
- [actionSheet addAction:action4];
- [actionSheet addAction:action5];
- //相当于之前的[actionSheet show];
- [weakSelf presentViewController:actionSheet animated:YES completion:nil];
- }else{
- UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
- UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"拍照" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf selectCamera];
-
- }];
- UIAlertAction *action2 = [UIAlertAction actionWithTitle:@"从手机相册选择" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf selectPhoto];
-
- }];
- UIAlertAction *action3 = [UIAlertAction actionWithTitle:@"查看上一张头像" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf SeeUpIcon];
-
- }];
- UIAlertAction *action4 = [UIAlertAction actionWithTitle:@"保存图片" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
- [weakSelf savePhoto];
-
- }];
- UIAlertAction *action5 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
- NSLog(@"取消");
- }];
- [action1 setValue:k6 forKey:@"_titleTextColor"];
- [action2 setValue:k6 forKey:@"_titleTextColor"];
- [action3 setValue:k6 forKey:@"_titleTextColor"];
- [action4 setValue:k6 forKey:@"_titleTextColor"];
- [action5 setValue:k6 forKey:@"_titleTextColor"];
- //把action添加到actionSheet里
- [actionSheet addAction:action1];
- [actionSheet addAction:action2];
- [actionSheet addAction:action3];
- [actionSheet addAction:action4];
- [actionSheet addAction:action5];
- //相当于之前的[actionSheet show];
- [weakSelf presentViewController:actionSheet animated:YES completion:nil];
- }
- }];
- }
- - (void)selectPhoto
- {
- WS(weakSelf);
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:1 delegate:nil];
- [imagePickerVc setNavLeftBarButtonSettingBlock:^(UIButton *leftButton){
- leftButton.hidden = YES;
- }];
- imagePickerVc.showSelectBtn = NO;
- imagePickerVc.allowCrop = YES;
- imagePickerVc.cropRect = CGRectMake(0, (SCREEN_HEIGHT - SCREEN_WIDTH) * 0.5, SCREEN_WIDTH, SCREEN_WIDTH);
- imagePickerVc.allowTakePicture = NO;
- imagePickerVc.allowTakeVideo = NO;
- imagePickerVc.allowPickingOriginalPhoto = NO;
- imagePickerVc.allowPickingGif = NO;
- [imagePickerVc setIsStatusBarDefault:YES];
- [imagePickerVc setNaviTitleColor:[UIColor blackColor]];
- [imagePickerVc setBarItemTextColor:[UIColor blackColor]];
- [imagePickerVc setDidFinishPickingPhotosHandle:^(NSArray<UIImage *> *photos, NSArray *assets, BOOL isSelectOriginalPhoto) {
- PHAsset *asset = assets.firstObject;
- switch (asset.mediaType) {
- case PHAssetMediaTypeVideo: {
-
- } break;
- case PHAssetMediaTypeImage: {
- UIImage * image = photos.firstObject;
- [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
-
- NSDictionary *dic = responseObject;
- NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]);
- NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]);
-
- [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) {
- REMOVESHOW;
- [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,UserDetailGet] parameters:@{} success:^(id _Nonnull responseObject) {
- NSDictionary *dic = responseObject;
- [[AppUserModel sharedAppUserModel] modelSetWithDictionary:dic];
- dispatch_async(dispatch_get_main_queue(), ^{
- weakSelf.iconView.image = image;
- });
- } failure:^(NSError * _Nonnull error) {
- }];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
-
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- } break;
- case PHAssetMediaTypeAudio:
- break;
- case PHAssetMediaTypeUnknown:
- break;
- default: break;
- }
- }];
- [self presentViewController:imagePickerVc animated:YES completion:nil];
- }
- - (void)selectCamera
- {
- WS(weakSelf);
- [[LYLPhotoTailoringTool sharedTool] selectPhotoWithPhoroOrCamera:SelectPhotoWithTypePhoroOrCamera2 crop:YES showImgBlock:^(NSString *imageUrlStr) {
- NSLog(@"111111");
- } choosImgBlock:^(UIImage *image) {
- NSLog(@"aaaaaa");
- SHOWLOADING
- [[HttpManager sharedHttpManager] HeaderUploadUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,Modify_UserImage_Post] parameters:@{@"":@""} pictureData:UIImageJPEGRepresentation(image,1.0f) pictureKey:@"file" success:^(id _Nonnull responseObject) {
- NSDictionary *dic = responseObject;
- NSLog(@"/n图片上传成功=====绝对路径=====/n%@",responseObject[@"AbsolutePath"]);
- NSLog(@"/n图片上传成功=====相对路径=====/n%@",responseObject[@"RelativePath"]);
- [UserManager updateUserInfoDetail:IMAGE Param:dic[@"RelativePath"] Success:^(id _Nonnull responseObject) {
- REMOVESHOW;
- [[HttpManager sharedHttpManager] GETUrl:[NSString stringWithFormat:@"%@%@",BaseUrl,UserDetailGet] parameters:@{} success:^(id _Nonnull responseObject) {
- NSDictionary *dic = responseObject;
- [[AppUserModel sharedAppUserModel] modelSetWithDictionary:dic];
- dispatch_async(dispatch_get_main_queue(), ^{
- weakSelf.iconView.image = image;
- });
- } failure:^(NSError * _Nonnull error) {
- }];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- } failure:^(NSError * _Nonnull error) {
- REMOVESHOW
- SHOWERROR([ZYCTool handerResultData:error])
- }];
- }];
- }
- - (void)SeeUpIcon
- {
- NSString * urlString = [AppUserModel sharedAppUserModel].HistoryAvatarUrl;
- if (urlString.length > 0) {
- MyUserIconVC * vc = [MyUserIconVC initMyUserIconVC];
- vc.HistoryVC = YES;
- [self.navigationController pushViewController:vc animated:YES];
- }else{
- [ShowtipTool showMessageWithStatus:@"没有历史头像"];
- }
- }
- - (void)savePhoto
- {
- WS(weakSelf);
- if (self.iconView.image) {
- NSError *error = nil;
- [[PHPhotoLibrary sharedPhotoLibrary] performChangesAndWait:^{
- [PHAssetChangeRequest creationRequestForAssetFromImage:weakSelf.iconView.image];
- } error:&error];
- if(error){
- [ShowtipTool showMessageWithStatus:@"保存失败"];
- }else{
- [ShowtipTool showMessageWithStatus:@"保存成功"];
- }
- }
- }
- @end
|