Commit 6b3bcfc47ef560fdb6247f6f3b0502d3aff1c3b0

Authored by zhangxiaowen
1 parent b19ee7ec

no message

CNLiveMineModule/Assets/CNLiveMineModule.xcassets/mine_info_set.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "mine_info_set@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "mine_info_set@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 23 \ No newline at end of file
... ...
CNLiveMineModule/Assets/CNLiveMineModule.xcassets/mine_info_set.imageset/mine_info_set@2x.png 0 → 100644

1.15 KB

CNLiveMineModule/Assets/CNLiveMineModule.xcassets/mine_info_set.imageset/mine_info_set@3x.png 0 → 100644

1.3 KB

CNLiveMineModule/Classes/Module/CNLiveMineService.m
... ... @@ -9,6 +9,7 @@
9 9 #import "CNLiveMineService.h"
10 10 #import "CNLiveServices.h"
11 11 #import "CNLiveMineController.h"
  12 +#import "CNLiveUserInfoController.h"
12 13  
13 14 @BeeHiveService(CNLiveMineServiceProtocol,CNLiveMineService)
14 15 @interface CNLiveMineService ()<CNLiveMineServiceProtocol>
... ... @@ -19,7 +20,6 @@
19 20  
20 21 // 我的
21 22 - (UIViewController *)getMineViewController {
22   -
23 23 return [CNLiveMineController new];
24 24 }
25 25  
... ... @@ -28,6 +28,16 @@
28 28 // [CNLivePageJumpManager pushViewController:vc];
29 29 }
30 30  
  31 +// 个人资料
  32 +- (UIViewController *)getUserInfoViewController {
  33 + return [CNLiveUserInfoController new];
  34 +}
  35 +
  36 +- (void)pushToUserInfoViewController {
  37 + CNLiveUserInfoController *vc = [[CNLiveUserInfoController alloc]init];
  38 +// [CNLivePageJumpManager pushViewController:vc];
  39 +}
  40 +
31 41  
32 42  
33 43 // 积分
... ...
CNLiveMineModule/Classes/UserInfo/CNLiveInfoUpdateController.m
... ... @@ -8,14 +8,17 @@
8 8  
9 9 #import "CNLiveInfoUpdateController.h"
10 10 #import "QMUIKit.h"
  11 +#import <SDWebImage/SDWebImage.h>
11 12  
12 13 #import "CNLiveUserInfoModel.h"
13 14 #import "CNLiveUserInfoNotification.h"
14 15 #import "CNLiveUserInfoNavigationBar.h"
15 16  
16   -@interface CNLiveInfoUpdateController ()<UITextFieldDelegate,UITextViewDelegate,CNLiveUserInfoNavigationBarDelegate>
  17 +@interface CNLiveInfoUpdateController ()<UITextFieldDelegate,UITextViewDelegate,CNLiveUserInfoNavigationBarDelegate,QMUIAlertControllerDelegate>
17 18 @property (nonatomic, strong) CNLiveUserInfoNavigationBar *navigationBar;
18 19 @property (nonatomic, strong) CNLiveUserInfoModel *model;
  20 +
  21 +@property (nonatomic, strong) UIImageView *imageView;
19 22 @property (nonatomic, weak) UITextField *textField;
20 23 @property (nonatomic, weak) UITextView *textView;
21 24  
... ... @@ -23,6 +26,7 @@
23 26  
24 27 @implementation CNLiveInfoUpdateController
25 28 static const NSInteger margin = 15;
  29 +static const CGFloat timeValue = 1.5;
26 30  
27 31 #pragma mark - 初始化方法
28 32 - (instancetype)initWithModel:(CNLiveUserInfoModel *)model{
... ... @@ -55,6 +59,12 @@ static const NSInteger margin = 15;
55 59 }
56 60 [self.view addSubview:self.navigationBar];
57 61 switch (self.model.dataType) {
  62 + case CNLiveUserInfoDataTypeHead:
  63 + {
  64 + self.navigationBar.title.text = @"个人头像";
  65 + [self image_layoutSubViews];
  66 + }
  67 + break;
58 68 case CNLiveUserInfoDataTypeNickname:
59 69 {
60 70 self.navigationBar.title.text = @"设置昵称";
... ... @@ -92,12 +102,27 @@ static const NSInteger margin = 15;
92 102  
93 103 }
94 104  
  105 +#pragma mark - 更新头像
  106 +- (void)image_layoutSubViews {
  107 + self.view.backgroundColor = [UIColor blackColor];
  108 +
  109 + UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_WIDTH)];
  110 + imageView.center = self.view.center;
  111 + imageView.backgroundColor = [UIColor whiteColor];// 设置背景颜色
  112 + UIImage *xw_image = [self xw_getImageName:@"default_avatar_f" bundleName:@"CNLiveMineModule" targetClass:[CNLiveInfoUpdateController class]];
  113 + [imageView sd_setImageWithURL:[NSURL URLWithString:@"头像"] placeholderImage:xw_image];
  114 + [self.view addSubview:imageView];
  115 + self.imageView = imageView;
  116 +
  117 +}
  118 +
  119 +#pragma mark - 更新昵称/地区
95 120 - (void)textField_layoutSubViews {
96   - UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, 50)];
  121 + UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationContentTop+margin, SCREEN_WIDTH, 50)];
97 122 bgView.backgroundColor = [UIColor whiteColor];
98 123 [self.view addSubview:bgView];
99 124  
100   - UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(margin, NavigationContentTop, SCREEN_WIDTH-2*margin, 50)];
  125 + UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(margin, NavigationContentTop+margin, SCREEN_WIDTH-2*margin, 50)];
101 126 textField.delegate = self;
102 127 textField.backgroundColor = [UIColor whiteColor];// 设置背景颜色
103 128 textField.textColor = [UIColor blackColor]; // 设置文字的颜色
... ... @@ -110,12 +135,13 @@ static const NSInteger margin = 15;
110 135  
111 136 }
112 137  
  138 +#pragma mark - 更新个性签名
113 139 - (void)textView_layoutSubViews {
114   - UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, 150)];
  140 + UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake(0, NavigationContentTop+margin, SCREEN_WIDTH, 150)];
115 141 bgView.backgroundColor = [UIColor whiteColor];
116 142 [self.view addSubview:bgView];
117 143  
118   - UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(margin, NavigationContentTop, SCREEN_WIDTH-2*margin, 150)];
  144 + UITextView *textView = [[UITextView alloc] initWithFrame:CGRectMake(margin, NavigationContentTop+margin, SCREEN_WIDTH-2*margin, 150)];
119 145 textView.delegate = self;
120 146 textView.backgroundColor = [UIColor whiteColor];// 设置背景颜色
121 147 textView.textColor = [UIColor blackColor]; // 设置文字的颜色
... ... @@ -163,22 +189,138 @@ static const NSInteger margin = 15;
163 189 - (void)textViewDidChange:(UITextView *)textView{
164 190  
165 191 }
  192 +#pragma mark - 私有方法
  193 +// 修改头像
  194 +- (void)updateHeaderActionSheetView{
  195 + __weak typeof(self) weakSelf = self;
  196 + QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"拍照" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  197 + __strong typeof(weakSelf) strongSelf = weakSelf;
  198 + if(!strongSelf) return ;
  199 +
  200 + self.navigationBar.right.userInteractionEnabled = YES;
  201 + }];
  202 + QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"从手机相册中选择" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  203 + __strong typeof(weakSelf) strongSelf = weakSelf;
  204 + if(!strongSelf) return ;
  205 + self.navigationBar.right.userInteractionEnabled = YES;
166 206  
167   -#pragma mark - 响应方法
168   -//回退goBack
169   -- (void)goBack {
170   - if (self.presentingViewController != nil) {
171   - [self dismissViewControllerAnimated:YES completion:nil];
  207 + }];
  208 + QMUIAlertAction *action3 = [QMUIAlertAction actionWithTitle:@"保存图片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  209 + __strong typeof(weakSelf) strongSelf = weakSelf;
  210 + if(!strongSelf) return ;
  211 + [strongSelf getPHAuthorizationStatus:^{
  212 + UIImage *image = [strongSelf generateImage:strongSelf.imageView];
  213 + [QMUITips showLoadingInView:strongSelf.view];
  214 + [strongSelf saveImage:image];
  215 + [QMUITips hideAllTipsInView:strongSelf.view];
  216 + }];
  217 + self.navigationBar.right.userInteractionEnabled = YES;
  218 +
  219 + }];
  220 + QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) {
  221 + __strong typeof(weakSelf) strongSelf = weakSelf;
  222 + if(!strongSelf) return ;
  223 + self.navigationBar.right.userInteractionEnabled = YES;
  224 +
  225 + }];
  226 +
  227 + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet];
  228 + alertController.delegate = self;
  229 + [alertController addAction:action1];
  230 + [alertController addAction:action2];
  231 + [alertController addAction:action3];
  232 + [alertController addAction:cancel];
  233 +
  234 + NSMutableDictionary *titleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  235 +
  236 + titleAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
  237 +
  238 + NSMutableDictionary *cancelAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes];
  239 + cancelAttributs[NSForegroundColorAttributeName] = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
  240 +
  241 + action1.buttonAttributes = titleAttributs;
  242 + action2.buttonAttributes = titleAttributs;
  243 + action3.buttonAttributes = titleAttributs;
  244 + cancel.buttonAttributes = cancelAttributs;
  245 +
  246 + [alertController showWithAnimated:YES];
  247 +}
  248 +
  249 +// 更新头像
  250 +- (void)requestUpdateUserHeader:(UIImage *)image{
  251 + // 数据请求更新
  252 +
  253 +}
  254 +- (void)getPHAuthorizationStatus:(void (^)(void))block{
  255 + // 1.获取当前App的相册授权状态
  256 + PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus];
  257 +
  258 + // 2.判断授权状态
  259 + if (authorizationStatus == PHAuthorizationStatusAuthorized) {
  260 + // 2.1 如果已经授权, 保存图片(调用步骤2的方法)
  261 + block();
  262 +
  263 + } else if (authorizationStatus == PHAuthorizationStatusNotDetermined) { // 如果没决定, 弹出指示框, 让用户选择
  264 + [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
  265 + // 如果用户选择授权, 则保存图片
  266 + if (status == PHAuthorizationStatusAuthorized) {
  267 + dispatch_async(dispatch_get_main_queue(), ^{
  268 + block();
  269 + });
  270 + }
  271 + }];
  272 +
  273 + } else {
  274 + NSDictionary *infoDict = [[NSBundle mainBundle] infoDictionary];
  275 + NSString *app_Name = [infoDict objectForKey:@"CFBundleDisplayName"];
  276 + if (app_Name == nil) {
  277 + app_Name = [infoDict objectForKey:@"CFBundleName"];
  278 + }
  279 + NSString *messageString = [NSString stringWithFormat:@"请在iPhone的\"设置 - 隐私 - 相机\"选项中,允许%@访问你的相册", app_Name];
  280 + UIAlertController *alertC = [UIAlertController alertControllerWithTitle:nil message:messageString preferredStyle:(UIAlertControllerStyleAlert)];
  281 + UIAlertAction *alertA = [UIAlertAction actionWithTitle:@"好" style:(UIAlertActionStyleDefault) handler:^(UIAlertAction * _Nonnull action) {
  282 +
  283 + }];
  284 +
  285 + [alertC addAction:alertA];
  286 + [self presentViewController:alertC animated:YES completion:nil];
172 287 }
173   - else {
174   - [self.navigationController popViewControllerAnimated:YES];
  288 +}
  289 +
  290 +// 保存图片
  291 +- (void)saveImage:(UIImage *)image{
  292 + if(!image){
  293 + [QMUITips showError:@"保存失败" inView:self.view hideAfterDelay:timeValue];
  294 + return;
175 295 }
  296 + [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{
  297 + [PHAssetChangeRequest creationRequestForAssetFromImage:image];
  298 +
  299 + } completionHandler:^(BOOL success, NSError * _Nullable error) {
  300 + dispatch_async(dispatch_get_main_queue(), ^{
  301 + if (success) {
  302 + [QMUITips showSucceed:@"保存成功" inView:self.view hideAfterDelay:timeValue];
  303 + } else {
  304 + [QMUITips showError:@"保存失败" inView:self.view hideAfterDelay:timeValue];
  305 + }
  306 + });
  307 +
  308 + }];
176 309 }
177   -- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
178   - [self.view endEditing:YES];
  310 +// UIView转UIImage
  311 +- (UIImage *)generateImage:(UIView *)view{
  312 + // 1.开启上下文
  313 + UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
  314 + // 2. 将控制器View的Layer渲染到上下文
  315 + [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  316 + // 3.取出图片
  317 + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  318 + // 4.结束上下文
  319 + UIGraphicsEndImageContext();
  320 +
  321 + return newImage;
179 322 }
180 323  
181   -#pragma mark - 私有方法
182 324 - (void)requestUpdateUserInfo:(NSString *)info{
183 325 // 数据请求更新
184 326  
... ... @@ -218,11 +360,32 @@ static const NSInteger margin = 15;
218 360  
219 361 }
220 362  
  363 +#pragma mark - 响应方法
  364 +//回退goBack
  365 +- (void)goBack {
  366 + if (self.presentingViewController != nil) {
  367 + [self dismissViewControllerAnimated:YES completion:nil];
  368 + }
  369 + else {
  370 + [self.navigationController popViewControllerAnimated:YES];
  371 + }
  372 +}
  373 +- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
  374 + [self.view endEditing:YES];
  375 +}
  376 +
  377 +#pragma mark - CNLiveUserInfoNavigationBarDelegate
221 378 - (void)navigationBar:(CNLiveUserInfoNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
222 379 if ([actionEvents isEqualToString:@"1"]) {
223 380 [self goBack];
224 381 }else if ([actionEvents isEqualToString:@"2"]){
225 382 switch (self.model.dataType) {
  383 + case CNLiveUserInfoDataTypeHead://头像
  384 + {
  385 + self.navigationBar.right.userInteractionEnabled = NO;
  386 + [self updateHeaderActionSheetView];
  387 + }
  388 + break;
226 389 case CNLiveUserInfoDataTypeNickname://昵称
227 390 case CNLiveUserInfoDataTypeAddress://地区
228 391 {
... ... @@ -240,24 +403,60 @@ static const NSInteger margin = 15;
240 403 }
241 404 }
242 405 }
  406 +
  407 +- (void)didHideAlertController:(QMUIAlertController *)alertController{
  408 + self.navigationBar.right.userInteractionEnabled = YES;
  409 +
  410 +}
  411 +
243 412 #pragma mark - 懒加载
244 413 - (CNLiveUserInfoNavigationBar *)navigationBar {
245 414 if (!_navigationBar) {
246 415 _navigationBar = [[CNLiveUserInfoNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  416 + _navigationBar.backgroundColor = [UIColor whiteColor];
247 417 _navigationBar.delegate = self;
248   - _navigationBar.title.text = @"个人资料";
249   - _navigationBar.right.frame = CGRectMake(SCREEN_WIDTH-44-15, StatusBarHeight+10, 44, 24);
250   - [_navigationBar.right setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
251   - _navigationBar.right.backgroundColor = [UIColor lightGrayColor];
252   - _navigationBar.right.userInteractionEnabled = NO;
253   - _navigationBar.right.titleLabel.font = [UIFont boldSystemFontOfSize:14];
254   - [_navigationBar.right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
255   - [_navigationBar.right setTitle:@"完成" forState:UIControlStateNormal];
256   - _navigationBar.right.adjustsImageWhenHighlighted = NO;
257   - _navigationBar.right.layer.masksToBounds = YES;
258   - _navigationBar.right.layer.cornerRadius = 5;
  418 + switch (self.model.dataType) {
  419 + case CNLiveUserInfoDataTypeHead:
  420 + {
  421 + UIImage *xw_image = [self xw_getImageName:@"mine_info_set" bundleName:@"CNLiveMineModule" targetClass:[CNLiveInfoUpdateController class]];
  422 + [_navigationBar.right setImage:xw_image forState:UIControlStateNormal];
  423 + }
  424 + break;
  425 + default:
  426 + {
  427 + _navigationBar.right.frame = CGRectMake(SCREEN_WIDTH-45-15, StatusBarHeight+10, 45, 24);
  428 + [_navigationBar.right setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
  429 + _navigationBar.right.backgroundColor = [UIColor lightGrayColor];
  430 + _navigationBar.right.userInteractionEnabled = NO;
  431 + _navigationBar.right.titleLabel.font = [UIFont boldSystemFontOfSize:13];
  432 + [_navigationBar.right setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  433 + [_navigationBar.right setTitle:@"完成" forState:UIControlStateNormal];
  434 + _navigationBar.right.adjustsImageWhenHighlighted = NO;
  435 + _navigationBar.right.layer.masksToBounds = YES;
  436 + _navigationBar.right.layer.cornerRadius = 5;
  437 + }
  438 + break;
  439 +
  440 + }
259 441 }
260 442 return _navigationBar;
261 443 }
262 444  
  445 +/**
  446 + * 创建图片
  447 + *
  448 + * @param imageName 图片名字
  449 + * @param bundleName 图片所在的bundle名字
  450 + * @param targetClass 类和bundle的同级目录
  451 + * @return 返回UIImage
  452 + */
  453 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  454 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  455 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  456 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  457 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  458 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  459 +
  460 +}
  461 +
263 462 @end
... ...
CNLiveMineModule/Classes/UserInfo/CNLiveUserInfoController.m
... ... @@ -145,7 +145,10 @@
145 145 switch (model.dataType) {
146 146 case CNLiveUserInfoDataTypeHead:
147 147 {
148   - [self updateHeaderActionSheetView];
  148 +// [self updateHeaderActionSheetView];
  149 + CNLiveInfoUpdateController *vc = [[CNLiveInfoUpdateController alloc]initWithModel:model];
  150 + vc.delegate = self;
  151 + [self.navigationController pushViewController:vc animated:YES];
149 152 }
150 153 break;
151 154 case CNLiveUserInfoDataTypeNickname:
... ... @@ -196,19 +199,6 @@
196 199 }
197 200 }
198 201 #pragma mark - 私有方法
199   -// 修改头像
200   -- (void)updateHeaderActionSheetView{
201   - __weak typeof(self) weakSelf = self;
202   -
203   -}
204   -
205   -// 更新头像
206   -- (void)requestUpdateUserHeader:(UIImage *)image{
207   - // 数据请求更新
208   -
209   -
210   -}
211   -
212 202 // 修改性别
213 203 - (void)updateGenderActionSheetView{
214 204 __weak typeof(self) weakSelf = self;
... ...