Commit 8306479e4a361099474e866e70f70f94b19097cf

Authored by zhangxiaowen
1 parent b059b30a

no message

CNLiveQrCodeModule.podspec
@@ -49,7 +49,7 @@ TODO: 网家家-二维码模块. @@ -49,7 +49,7 @@ TODO: 网家家-二维码模块.
49 s.dependency 'CNLiveTripartiteManagement/SDWebImage' 49 s.dependency 'CNLiveTripartiteManagement/SDWebImage'
50 s.dependency 'CNLiveTripartiteManagement/Masonry' 50 s.dependency 'CNLiveTripartiteManagement/Masonry'
51 s.dependency 'CNLiveTripartiteManagement/MJExtension' 51 s.dependency 'CNLiveTripartiteManagement/MJExtension'
52 - s.dependency 'SGQRCode' 52 + s.dependency 'SGQRCode', '3.0.1'
53 53
54 # 服务层 54 # 服务层
55 s.dependency 'CNLiveServices' 55 s.dependency 'CNLiveServices'
CNLiveQrCodeModule/Assets/CNLiveQrCodeModule.xcassets/code_back_black_b.imageset/Contents.json 0 → 100644
  1 +{
  2 + "images" : [
  3 + {
  4 + "idiom" : "universal",
  5 + "scale" : "1x"
  6 + },
  7 + {
  8 + "idiom" : "universal",
  9 + "filename" : "code_back_black_b@2x.png",
  10 + "scale" : "2x"
  11 + },
  12 + {
  13 + "idiom" : "universal",
  14 + "filename" : "code_back_black_b@3x.png",
  15 + "scale" : "3x"
  16 + }
  17 + ],
  18 + "info" : {
  19 + "version" : 1,
  20 + "author" : "xcode"
  21 + }
  22 +}
0 \ No newline at end of file 23 \ No newline at end of file
CNLiveQrCodeModule/Assets/CNLiveQrCodeModule.xcassets/code_back_black_b.imageset/code_back_black_b@2x.png 0 → 100644

1.49 KB

CNLiveQrCodeModule/Assets/CNLiveQrCodeModule.xcassets/code_back_black_b.imageset/code_back_black_b@3x.png 0 → 100644

1.79 KB

CNLiveQrCodeModule/Classes/Controller/CNLiveGroupQrCodeController.h
@@ -14,9 +14,11 @@ @@ -14,9 +14,11 @@
14 #import <UIKit/UIKit.h> 14 #import <UIKit/UIKit.h>
15 15
16 NS_ASSUME_NONNULL_BEGIN 16 NS_ASSUME_NONNULL_BEGIN
  17 +@class IMAGroup;
17 18
18 @interface CNLiveGroupQrCodeController : UIViewController 19 @interface CNLiveGroupQrCodeController : UIViewController
19 @property (nonatomic, assign) BOOL isScanCode; 20 @property (nonatomic, assign) BOOL isScanCode;
  21 +@property (nonatomic, strong) IMAGroup *group;
20 22
21 @end 23 @end
22 24
CNLiveQrCodeModule/Classes/Controller/CNLiveGroupQrCodeController.m
@@ -7,67 +7,190 @@ @@ -7,67 +7,190 @@
7 // 7 //
8 8
9 #import "CNLiveGroupQrCodeController.h" 9 #import "CNLiveGroupQrCodeController.h"
10 - 10 +#import <Masonry/Masonry.h>
11 #import "QMUIKit.h" 11 #import "QMUIKit.h"
  12 +#import "SGQRCode.h"//二维码库
12 13
13 #import "CNLiveQrCodeNavigationBar.h" 14 #import "CNLiveQrCodeNavigationBar.h"
  15 +#import "CNLiveGroupQrcodeView.h"
  16 +#import "CNLiveQrCodeNavigationBar.h"
14 17
15 -@interface CNLiveGroupQrCodeController() 18 +@interface CNLiveGroupQrCodeController ()<CNLiveQrCodeNavigationBarDelegate>
  19 +@property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar;
  20 +@property (nonatomic, strong) CNLiveGroupQrCodeView *groupView;
  21 +@property (nonatomic, strong) UIButton *save;
  22 +@property (nonatomic, strong) UIButton *share;
16 23
17 @end 24 @end
18 25
19 @implementation CNLiveGroupQrCodeController 26 @implementation CNLiveGroupQrCodeController
20 -static const NSInteger kHEIGHT = 250;  
21 -  
22 -#pragma mark - 加载数据  
23 -- (void)loadData {  
24 -  
25 -  
26 -}  
27 - 27 +static const NSInteger margin = 10;
28 #pragma mark - 生命周期 28 #pragma mark - 生命周期
29 - (void)viewWillAppear:(BOOL)animated{ 29 - (void)viewWillAppear:(BOOL)animated{
30 [super viewWillAppear:animated]; 30 [super viewWillAppear:animated];
31 self.navigationController.navigationBarHidden = YES; 31 self.navigationController.navigationBarHidden = YES;
32 -  
33 } 32 }
34 33
35 - (void)viewDidLoad { 34 - (void)viewDidLoad {
36 [super viewDidLoad]; 35 [super viewDidLoad];
37 - self.view.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0];  
38 - [self createSubViews];  
39 - [self loadData];  
40 -}  
41 -  
42 -- (void)dealloc { 36 + // Do any additional setup after loading the view.
  37 + self.view.backgroundColor = [UIColor colorWithRed:245/255.0 green:245/255.0 blue:249/255.0 alpha:1.0];
  38 + [self.view addSubview:self.navigationBar];
  39 + [self.view addSubview:self.groupView];
43 40
  41 + [self.view addSubview:self.save];
  42 + CGFloat width = (SCREEN_WIDTH-6*margin)/2.0;
  43 + [self.save mas_makeConstraints:^(MASConstraintMaker *make) {
  44 + make.left.mas_equalTo(self.view.mas_left).mas_offset(2.5*margin);
  45 + make.top.mas_equalTo(self.groupView.mas_bottom).mas_offset(2*margin);
  46 + make.width.mas_equalTo(width);
  47 + make.height.mas_equalTo(40);
  48 +
  49 + }];
44 50
  51 + [self.view addSubview:self.share];
  52 + [self.share mas_makeConstraints:^(MASConstraintMaker *make) {
  53 + make.left.mas_equalTo(self.save.mas_right).mas_offset(margin);
  54 + make.top.mas_equalTo(self.save.mas_top);
  55 + make.width.mas_equalTo(self.save.mas_width);
  56 + make.height.mas_equalTo(self.save.mas_height);
  57 +
  58 + }];
45 } 59 }
46 60
47 -- (void)createSubViews {  
48 - 61 +/*
  62 +#pragma mark - Navigation
  63 +
  64 +// In a storyboard-based application, you will often want to do a little preparation before navigation
  65 +- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
  66 + // Get the new view controller using [segue destinationViewController].
  67 + // Pass the selected object to the new view controller.
49 } 68 }
  69 +*/
50 70
51 -#pragma mark - 状态栏  
52 -/**  
53 - * 状态栏的颜色  
54 - *  
55 - * @return UIStatusBarStyle  
56 - *  
57 - */  
58 -- (UIStatusBarStyle)preferredStatusBarStyle{  
59 - return UIStatusBarStyleLightContent;  
60 - 71 +#pragma mark - 代理
  72 +- (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
  73 + if ([actionEvents isEqualToString:@"1"]) {
  74 + [self goBack];
  75 + }
61 } 76 }
62 77
63 #pragma mark - 懒加载 78 #pragma mark - 懒加载
64 - 79 +- (CNLiveQrCodeNavigationBar *)navigationBar {
  80 + if (!_navigationBar) {
  81 + _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  82 + _navigationBar.backgroundColor = [UIColor whiteColor];
  83 + _navigationBar.delegate = self;
  84 + UIImage *image = [self xw_getImageName:@"code_back_black_b" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeController class]];
  85 + [_navigationBar.left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  86 + _navigationBar.title.text = @"群二维码名片";
  87 + _navigationBar.title.textColor = [UIColor blackColor];
  88 + _navigationBar.right = nil;
  89 + }
  90 + return _navigationBar;
  91 +}
  92 +- (CNLiveGroupQrCodeView *)groupView {
  93 + if (!_groupView) {
  94 + _groupView = [[CNLiveGroupQrCodeView alloc] initWithFrame:CGRectMake(0, 0, 310, 342)];
  95 + _groupView.center = CGPointMake(self.view.center.x, self.view.center.y-20);
  96 + _groupView.layer.masksToBounds = YES;
  97 + _groupView.layer.cornerRadius = 10;
  98 +// _groupView.group = self.group;
  99 + }
  100 + return _groupView;
  101 +}
  102 +- (UIButton *)save{
  103 + if(!_save){
  104 + _save = [UIButton buttonWithType:UIButtonTypeCustom];
  105 + _save.titleLabel.font = [UIFont systemFontOfSize:16.0];
  106 + _save.backgroundColor = [UIColor whiteColor];
  107 + _save.layer.cornerRadius = 5;
  108 + _save.layer.masksToBounds = YES;
  109 + [_save addTarget:self action:@selector(saveBtnDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  110 + [_save setTitle:@"保存到手机" forState:UIControlStateNormal];
  111 + [_save setTitleColor:[UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0] forState:UIControlStateNormal];
  112 + _save.backgroundColor = [UIColor colorWithRed:234/255.0 green:236/255.0 blue:244/255.0 alpha:1.0];
  113 +
  114 + }
  115 + return _save;
  116 +
  117 +}
  118 +- (UIButton *)share{
  119 + if(!_share){
  120 + _share = [UIButton buttonWithType:UIButtonTypeCustom];
  121 + _share.titleLabel.font = [UIFont systemFontOfSize:16.0];
  122 + _share.backgroundColor = [UIColor whiteColor];
  123 + _share.layer.cornerRadius = 5;
  124 + _share.layer.masksToBounds = YES;
  125 + [_share addTarget:self action:@selector(shareDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  126 + [_share setTitle:@"分享二维码" forState:UIControlStateNormal];
  127 + [_share setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  128 + _share.backgroundColor = [UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0];
  129 +
  130 + }
  131 + return _share;
  132 +
  133 +}
65 134
66 #pragma mark - 响应方法 135 #pragma mark - 响应方法
67 -- (void)soccerDidClicked:(UIButton *)btn{ 136 +- (void)goBack {
  137 + if (self.presentingViewController != nil) {
  138 + [self dismissViewControllerAnimated:YES completion:nil];
  139 +
  140 + }
  141 + else {
  142 + [self.navigationController popViewControllerAnimated:YES];
  143 + }
  144 +}
  145 +#pragma mark - 保存到手机
  146 +- (void)saveBtnDidClicked:(UIButton *)btn{
  147 + UIImage *image = [self generateImage:self.groupView];
  148 + [QMUITips showLoadingInView:self.view];
  149 + [self saveImage:image];
  150 + [QMUITips hideAllTipsInView:self.view];
  151 +
  152 +}
  153 +
  154 +- (void)saveImage:(UIImage *)image {
  155 + [[PHPhotoLibrary sharedPhotoLibrary] performChanges:^{
  156 + [PHAssetChangeRequest creationRequestForAssetFromImage:image];
  157 +
  158 + } completionHandler:^(BOOL success, NSError * _Nullable error) {
  159 + if (!success) return ;
  160 + dispatch_async(dispatch_get_main_queue(), ^{
  161 + [QMUITips showSucceed:@"已保存到系统相册" inView:self.view hideAfterDelay:1.5];
  162 + });
  163 + }];
68 164
69 } 165 }
70 166
  167 +#pragma mark - 分享二维码
  168 +- (void)shareDidClicked:(UIButton *)btn{
  169 + UIImage *image = [self generateImage:self.groupView];
  170 + NSArray *imageArray = @[@"sport_china_download"].copy;
  171 + NSArray *titleArray = @[@"保存"].copy;
  172 + __weak typeof(self) weakSelf = self;
  173 +// [CNLiveShareManager showShareViewWithParamForShareTitle:nil ShareUrl:nil ShareDesc:nil ShareImage:image ScreenFull:NO HiddenWjj:NO HiddenQQ:NO HiddenWB:NO HiddenWechat:NO HiddenSafari:YES TopImage:imageArray TopTitles:titleArray PlatformType:CNLiveSharePlatformTypeAll TouchActionBlock:^(NSString *title) {
  174 +//
  175 +// } CompleterBlock:^(CNLiveShareResultType resultType, CNLiveSharePlatformType platformType, NSString *typtString) {
  176 +//
  177 +// }];
  178 +}
  179 +
  180 +// UIView转UIImage
  181 +- (UIImage *)generateImage:(UIView *)view{
  182 + // 1.开启上下文
  183 + UIGraphicsBeginImageContextWithOptions(view.frame.size, NO, 0.0);
  184 + // 2. 将控制器View的Layer渲染到上下文
  185 + [view.layer renderInContext:UIGraphicsGetCurrentContext()];
  186 + // 3.取出图片
  187 + UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
  188 + // 4.结束上下文
  189 + UIGraphicsEndImageContext();
  190 +
  191 + return newImage;
  192 +}
  193 +
71 /** 194 /**
72 * 创建图片 195 * 创建图片
73 * 196 *
CNLiveQrCodeModule/Classes/Controller/CNLiveMyQrCodeController.m
@@ -7,23 +7,20 @@ @@ -7,23 +7,20 @@
7 // 7 //
8 8
9 #import "CNLiveMyQrCodeController.h" 9 #import "CNLiveMyQrCodeController.h"
10 -#import "QMUIKit.h"  
11 -  
12 #import <Photos/Photos.h> 10 #import <Photos/Photos.h>
13 #import <Accelerate/Accelerate.h> 11 #import <Accelerate/Accelerate.h>
14 12
  13 +#import "QMUIKit.h"
15 #import <Masonry/Masonry.h> 14 #import <Masonry/Masonry.h>
16 #import <SDWebImage/SDWebImage.h> 15 #import <SDWebImage/SDWebImage.h>
17 16
18 -  
19 -#import "CNLiveMyQrCodeView.h"  
20 #import "CNLiveQrCodeNavigationBar.h" 17 #import "CNLiveQrCodeNavigationBar.h"
  18 +#import "CNLiveMyQrCodeView.h"
21 19
22 @interface CNLiveMyQrCodeController ()<CNLiveQrCodeNavigationBarDelegate> 20 @interface CNLiveMyQrCodeController ()<CNLiveQrCodeNavigationBarDelegate>
23 @property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar; 21 @property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar;
24 -@property (nonatomic, weak) UIImageView *bgView;  
25 -@property (nonatomic, weak) CNLiveMyQrCodeView *qrCodeView;  
26 -@property (nonatomic, weak) UIButton *rightBtn; 22 +@property (nonatomic, strong) UIImageView *bgView;
  23 +@property (nonatomic, strong) CNLiveMyQrCodeView *qrCodeView;
27 24
28 @end 25 @end
29 26
@@ -54,20 +51,8 @@ static const CGFloat timeValue = 1.5; @@ -54,20 +51,8 @@ static const CGFloat timeValue = 1.5;
54 } 51 }
55 52
56 - (void)createSubViews { 53 - (void)createSubViews {
57 - UIImageView *bgView = [[UIImageView alloc]initWithFrame:self.view.bounds];  
58 - UIImage *image = [self xw_getImageName:@"qr_code_bg" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveMyQrCodeController class]];  
59 - [bgView sd_setImageWithURL:[NSURL URLWithString:@"User_Head"] placeholderImage:image completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {  
60 - if(image){  
61 -// bgView.image = [image blurImageWithRadius:4];  
62 - }  
63 - }];  
64 - [self.view addSubview:bgView];  
65 - self.bgView = bgView;  
66 -  
67 - CNLiveMyQrCodeView *qrCodeView = [[CNLiveMyQrCodeView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-2*margin, 420)];  
68 - qrCodeView.center = self.view.center;  
69 - [self.view addSubview:qrCodeView];  
70 - self.qrCodeView = qrCodeView; 54 + [self.view addSubview:self.bgView];
  55 + [self.view addSubview:self.qrCodeView];
71 [self.view addSubview:self.navigationBar]; 56 [self.view addSubview:self.navigationBar];
72 57
73 } 58 }
@@ -201,15 +186,35 @@ static const CGFloat timeValue = 1.5; @@ -201,15 +186,35 @@ static const CGFloat timeValue = 1.5;
201 }]; 186 }];
202 } 187 }
203 188
204 -#pragma mark - 懒加载 189 +#pragma mark - 代理
205 - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ 190 - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
206 if ([actionEvents isEqualToString:@"1"]) { 191 if ([actionEvents isEqualToString:@"1"]) {
207 [self goBack]; 192 [self goBack];
208 } 193 }
209 } 194 }
  195 +#pragma mark - 懒加载
  196 +- (UIImageView *)bgView{
  197 + if(!_bgView){
  198 + _bgView = [[UIImageView alloc]initWithFrame:self.view.bounds];
  199 + UIImage *image = [self xw_getImageName:@"qr_code_bg" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveMyQrCodeController class]];
  200 + [_bgView sd_setImageWithURL:[NSURL URLWithString:@"User_Head"] placeholderImage:image completed:^(UIImage * _Nullable image, NSError * _Nullable error, SDImageCacheType cacheType, NSURL * _Nullable imageURL) {
  201 + if(image){
  202 + // bgView.image = [image blurImageWithRadius:4];
  203 + }
  204 + }];
  205 + }
  206 + return _bgView;
  207 +}
  208 +- (CNLiveMyQrCodeView *)qrCodeView {
  209 + if (!_qrCodeView) {
  210 + _qrCodeView = [[CNLiveMyQrCodeView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH-2*margin, 420)];
  211 + _qrCodeView.center = self.view.center;
  212 + }
  213 + return _qrCodeView;
  214 +}
210 - (CNLiveQrCodeNavigationBar *)navigationBar { 215 - (CNLiveQrCodeNavigationBar *)navigationBar {
211 if (!_navigationBar) { 216 if (!_navigationBar) {
212 - _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, NavigationContentTop)]; 217 + _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
213 _navigationBar.delegate = self; 218 _navigationBar.delegate = self;
214 _navigationBar.title.text = @"我的二维码"; 219 _navigationBar.title.text = @"我的二维码";
215 UIImage *image2 = [self xw_getImageName:@"mine_code_more" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveMyQrCodeController class]]; 220 UIImage *image2 = [self xw_getImageName:@"mine_code_more" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveMyQrCodeController class]];
CNLiveQrCodeModule/Classes/Controller/CNLiveScanQrCodeController.m
@@ -16,7 +16,7 @@ @@ -16,7 +16,7 @@
16 #import "CNLiveMyQrCodeController.h" 16 #import "CNLiveMyQrCodeController.h"
17 #import "CNLiveQrCodeNavigationBar.h" 17 #import "CNLiveQrCodeNavigationBar.h"
18 18
19 -//#import "XWScanSuccessController.h" 19 +#import "CNLiveScanResultController.h"
20 20
21 @interface CNLiveScanQrCodeController ()<CNLiveQrCodeNavigationBarDelegate>{ 21 @interface CNLiveScanQrCodeController ()<CNLiveQrCodeNavigationBarDelegate>{
22 SGQRCodeObtain *obtain; 22 SGQRCodeObtain *obtain;
@@ -151,9 +151,10 @@ static const CGFloat timeValue = 1.5; @@ -151,9 +151,10 @@ static const CGFloat timeValue = 1.5;
151 151
152 [obtain establishQRCodeObtainScanWithController:self configure:configure]; 152 [obtain establishQRCodeObtainScanWithController:self configure:configure];
153 [obtain startRunningWithBefore:^{ 153 [obtain startRunningWithBefore:^{
154 -// [SVProgressHUD showWithStatus:@"正在加载..."]; 154 + [QMUITips showInfo:@"正在加载..."];
  155 +
155 } completion:^{ 156 } completion:^{
156 -// [SVProgressHUD dismiss]; 157 + [QMUITips hideAllTips];
157 }]; 158 }];
158 [obtain setBlockWithQRCodeObtainScanResult:^(SGQRCodeObtain *obtain, NSString *result) { 159 [obtain setBlockWithQRCodeObtainScanResult:^(SGQRCodeObtain *obtain, NSString *result) {
159 __strong typeof(weakSelf) strongSelf = weakSelf; 160 __strong typeof(weakSelf) strongSelf = weakSelf;
@@ -228,9 +229,9 @@ static const CGFloat timeValue = 1.5; @@ -228,9 +229,9 @@ static const CGFloat timeValue = 1.5;
228 } 229 }
229 // 不是app的业务 230 // 不是app的业务
230 else{ 231 else{
231 -// XWScanSuccessController *jumpVC = [[XWScanSuccessController alloc] init];  
232 -// jumpVC.jump_URL = result;  
233 -// [self.navigationController pushViewController:jumpVC animated:YES]; 232 + CNLiveScanResultController *jumpVC = [[CNLiveScanResultController alloc] init];
  233 + jumpVC.jump_URL = result;
  234 + [self.navigationController pushViewController:jumpVC animated:YES];
234 } 235 }
235 236
236 } 237 }
@@ -267,15 +268,16 @@ static const CGFloat timeValue = 1.5; @@ -267,15 +268,16 @@ static const CGFloat timeValue = 1.5;
267 return UIStatusBarStyleLightContent; 268 return UIStatusBarStyleLightContent;
268 269
269 } 270 }
270 -#pragma mark - 懒加载 271 +#pragma mark - 代理
271 - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ 272 - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
272 if ([actionEvents isEqualToString:@"1"]) { 273 if ([actionEvents isEqualToString:@"1"]) {
273 [self goBack]; 274 [self goBack];
274 } 275 }
275 } 276 }
  277 +#pragma mark - 懒加载
276 - (CNLiveQrCodeNavigationBar *)navigationBar { 278 - (CNLiveQrCodeNavigationBar *)navigationBar {
277 if (!_navigationBar) { 279 if (!_navigationBar) {
278 - _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, NavigationContentTop)]; 280 + _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
279 _navigationBar.delegate = self; 281 _navigationBar.delegate = self;
280 _navigationBar.title.text = @"扫一扫"; 282 _navigationBar.title.text = @"扫一扫";
281 [_navigationBar.right setTitle:@"相册" forState:UIControlStateNormal]; 283 [_navigationBar.right setTitle:@"相册" forState:UIControlStateNormal];
@@ -291,7 +293,7 @@ static const CGFloat timeValue = 1.5; @@ -291,7 +293,7 @@ static const CGFloat timeValue = 1.5;
291 - (UIButton *)flashlightBtn { 293 - (UIButton *)flashlightBtn {
292 if (!_flashlightBtn) { 294 if (!_flashlightBtn) {
293 _flashlightBtn = [UIButton buttonWithType:UIButtonTypeCustom]; 295 _flashlightBtn = [UIButton buttonWithType:UIButtonTypeCustom];
294 - CGFloat flashlightBtnW = 60; 296 + CGFloat flashlightBtnW = 100;
295 CGFloat flashlightBtnH = 50; 297 CGFloat flashlightBtnH = 50;
296 CGFloat flashlightBtnX = 0.5 * (self.view.frame.size.width - flashlightBtnW); 298 CGFloat flashlightBtnX = 0.5 * (self.view.frame.size.width - flashlightBtnW);
297 CGFloat flashlightBtnY = 0.55 * self.view.frame.size.height; 299 CGFloat flashlightBtnY = 0.55 * self.view.frame.size.height;
@@ -300,7 +302,14 @@ static const CGFloat timeValue = 1.5; @@ -300,7 +302,14 @@ static const CGFloat timeValue = 1.5;
300 UIImage *image2 = [self xw_getImageName:@"flashlight_open" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveScanQrCodeController class]]; 302 UIImage *image2 = [self xw_getImageName:@"flashlight_open" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveScanQrCodeController class]];
301 [_flashlightBtn setImage:image1 forState:UIControlStateNormal]; 303 [_flashlightBtn setImage:image1 forState:UIControlStateNormal];
302 [_flashlightBtn setImage:image2 forState:UIControlStateSelected]; 304 [_flashlightBtn setImage:image2 forState:UIControlStateSelected];
  305 + [_flashlightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
  306 + [_flashlightBtn setTitleColor:[UIColor greenColor] forState:UIControlStateSelected];
  307 + [_flashlightBtn setTitle:@"轻触点亮" forState:UIControlStateNormal];
  308 + [_flashlightBtn setTitle:@"轻触关闭" forState:UIControlStateSelected];
  309 + _flashlightBtn.titleLabel.font = [UIFont systemFontOfSize:13];
303 [_flashlightBtn addTarget:self action:@selector(flashlightButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside]; 310 [_flashlightBtn addTarget:self action:@selector(flashlightButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
  311 + _flashlightBtn.titleEdgeInsets = UIEdgeInsetsMake(_flashlightBtn.imageView.frame.size.height+10, -_flashlightBtn.imageView.frame.size.width, 0, 0);
  312 + _flashlightBtn.imageEdgeInsets = UIEdgeInsetsMake(-_flashlightBtn.titleLabel.bounds.size.height, 0, 10, -_flashlightBtn.titleLabel.bounds.size.width);
304 } 313 }
305 return _flashlightBtn; 314 return _flashlightBtn;
306 315
@@ -325,18 +334,20 @@ static const CGFloat timeValue = 1.5; @@ -325,18 +334,20 @@ static const CGFloat timeValue = 1.5;
325 - (UIButton *)codeButton { 334 - (UIButton *)codeButton {
326 if (!_codeButton) { 335 if (!_codeButton) {
327 _codeButton = [UIButton buttonWithType:(UIButtonTypeCustom)]; 336 _codeButton = [UIButton buttonWithType:(UIButtonTypeCustom)];
328 - CGFloat flashlightBtnW = 120; 337 + CGFloat flashlightBtnW = 100;
329 CGFloat flashlightBtnH = 50; 338 CGFloat flashlightBtnH = 50;
330 CGFloat flashlightBtnX = 0.5 * (self.view.frame.size.width - flashlightBtnW); 339 CGFloat flashlightBtnX = 0.5 * (self.view.frame.size.width - flashlightBtnW);
331 CGFloat flashlightBtnY = CGRectGetMaxY(self.promptLabel.frame)+15; 340 CGFloat flashlightBtnY = CGRectGetMaxY(self.promptLabel.frame)+15;
332 _codeButton.frame = CGRectMake(flashlightBtnX, flashlightBtnY, flashlightBtnW, flashlightBtnH); 341 _codeButton.frame = CGRectMake(flashlightBtnX, flashlightBtnY, flashlightBtnW, flashlightBtnH);
333 UIImage *image = [self xw_getImageName:@"qr_code_green" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveScanQrCodeController class]]; 342 UIImage *image = [self xw_getImageName:@"qr_code_green" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveScanQrCodeController class]];
334 [_codeButton setImage:image forState:UIControlStateNormal]; 343 [_codeButton setImage:image forState:UIControlStateNormal];
335 - [_codeButton setTitle:@" 我的二维码" forState:UIControlStateNormal]; 344 + [_codeButton setTitle:@"我的二维码" forState:UIControlStateNormal];
336 _codeButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15.0f]; 345 _codeButton.titleLabel.font = [UIFont fontWithName:@"PingFang-SC-Regular" size:15.0f];
337 [_codeButton setTitleColor:[UIColor colorWithRed:26/255.0 green:161/255.0 blue:45/255.0 alpha:1.0] forState:UIControlStateNormal]; 346 [_codeButton setTitleColor:[UIColor colorWithRed:26/255.0 green:161/255.0 blue:45/255.0 alpha:1.0] forState:UIControlStateNormal];
338 [_codeButton addTarget:self action:@selector(codeButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside]; 347 [_codeButton addTarget:self action:@selector(codeButtonDidClicked:) forControlEvents:UIControlEventTouchUpInside];
339 [_codeButton setAdjustsImageWhenHighlighted:NO]; 348 [_codeButton setAdjustsImageWhenHighlighted:NO];
  349 + _codeButton.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 20);
  350 + _codeButton.imageEdgeInsets = UIEdgeInsetsMake(0, 80, 0, -80);
340 } 351 }
341 return _codeButton; 352 return _codeButton;
342 353
CNLiveQrCodeModule/Classes/Controller/CNLiveScanResultController.h 0 → 100755
  1 +//
  2 +// CNLiveScanResultController.h
  3 +// CNLiveQrCodeModule
  4 +//
  5 +// Created by 153993236@qq.com on 11/12/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import <UIKit/UIKit.h>
  10 +
  11 +@interface CNLiveScanResultController : UIViewController
  12 +/** 是否返回到Root */
  13 +@property (nonatomic, assign) BOOL isPopToRoot;
  14 +@property (nonatomic, copy) NSString *jump_URL;
  15 +
  16 +@end
CNLiveQrCodeModule/Classes/Controller/CNLiveScanResultController.m 0 → 100755
  1 +//
  2 +// CNLiveScanResultController.m
  3 +// CNLiveQrCodeModule
  4 +//
  5 +// Created by 153993236@qq.com on 11/12/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveScanResultController.h"
  10 +#import "QMUIKit.h"
  11 +
  12 +#import "CNLiveQrCodeNavigationBar.h"
  13 +#import "CNLiveWebView.h"
  14 +
  15 +@interface CNLiveScanResultController () <CNLiveQrCodeNavigationBarDelegate, CNLiveWebViewDelegate>
  16 +@property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar;
  17 +@property (nonatomic, strong) CNLiveWebView *webView;
  18 +
  19 +@end
  20 +
  21 +@implementation CNLiveScanResultController
  22 +#pragma mark - 生命周期
  23 +- (void)viewWillAppear:(BOOL)animated{
  24 + [super viewWillAppear:animated];
  25 + self.navigationController.navigationBarHidden = YES;
  26 +}
  27 +
  28 +- (void)viewDidLoad {
  29 + [super viewDidLoad];
  30 + // Do any additional setup after loading the view.
  31 + self.view.backgroundColor = [UIColor whiteColor];
  32 + [self setupSubView];
  33 +
  34 + if ([self.jump_URL hasPrefix:@"http://"]||[self.jump_URL hasPrefix:@"https://"]) {
  35 + [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.jump_URL]]];
  36 +
  37 + } else {
  38 + [_webView loadHTMLString:[self html:self.jump_URL]];
  39 + }
  40 +}
  41 +
  42 +- (NSString *)html:(NSString *)url{
  43 + return [NSString stringWithFormat:@"<div style=\"font-size:40px\">%@</div>",url];
  44 +}
  45 +
  46 +- (void)setupSubView {
  47 + [self.view addSubview:self.navigationBar];
  48 + [self.view addSubview:self.webView];
  49 +}
  50 +
  51 +- (void)webView:(CNLiveWebView *)webView didFinishLoadWithURL:(NSURL *)url {
  52 + NSLog(@"didFinishLoad");
  53 + if(webView.navigationItemTitle.length != 0){
  54 + self.navigationBar.title.text = webView.navigationItemTitle;
  55 + }else{
  56 + self.navigationBar.title.text = @"识别结果";
  57 +
  58 + }
  59 +
  60 +}
  61 +#pragma mark - 代理
  62 +- (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{
  63 + if ([actionEvents isEqualToString:@"1"]) {
  64 +// [self goBack];
  65 + }
  66 +}
  67 +
  68 +- (void)webView:(CNLiveWebView *)webView didFailLoadWithError:(NSError *)error{
  69 +
  70 +}
  71 +
  72 +#pragma mark - 懒加载
  73 +- (CNLiveQrCodeNavigationBar *)navigationBar {
  74 + if (!_navigationBar) {
  75 + _navigationBar = [[CNLiveQrCodeNavigationBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, NavigationContentTop)];
  76 + _navigationBar.delegate = self;
  77 + _navigationBar.title.textColor = [UIColor blackColor];
  78 + _navigationBar.delegate = self;
  79 +
  80 + UIImage *image = [self xw_getImageName:@"code_back_black_b" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveScanResultController class]];
  81 + [_navigationBar.left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
  82 + _navigationBar.right = nil;
  83 +
  84 + }
  85 + return _navigationBar;
  86 +}
  87 +
  88 +- (CNLiveWebView *)webView {
  89 + if (!_webView) {
  90 + _webView = [CNLiveWebView webViewWithFrame:CGRectMake(0, NavigationContentTop, SCREEN_WIDTH, SCREEN_HEIGHT-NavigationContentTop)];
  91 + _webView.isNavigationBarOrTranslucent = NO;
  92 + _webView.delegate = self;
  93 + }
  94 + return _webView;
  95 +}
  96 +
  97 +/**
  98 + * 创建图片
  99 + *
  100 + * @param imageName 图片名字
  101 + * @param bundleName 图片所在的bundle名字
  102 + * @param targetClass 类和bundle的同级目录
  103 + * @return 返回UIImage
  104 + */
  105 +- (UIImage *)xw_getImageName:(NSString *)imageName bundleName:(NSString *)bundleName targetClass:(Class)targetClass{
  106 + NSBundle *bundle = [NSBundle bundleForClass:targetClass];
  107 + NSURL *url = [bundle URLForResource:bundleName withExtension:@"bundle"];
  108 + NSBundle *targetBundle = [NSBundle bundleWithURL:url];
  109 + UIImage *image = [UIImage imageNamed:imageName inBundle:targetBundle compatibleWithTraitCollection:nil];
  110 + return image?image:[UIImage imageNamed:imageName inBundle:[NSBundle mainBundle] compatibleWithTraitCollection:nil];
  111 +}
  112 +
  113 +@end
CNLiveQrCodeModule/Classes/View/CNLiveGroupQrCodeView.m
@@ -10,278 +10,127 @@ @@ -10,278 +10,127 @@
10 #import <Masonry/Masonry.h> 10 #import <Masonry/Masonry.h>
11 #import <SDWebImage/SDWebImage.h> 11 #import <SDWebImage/SDWebImage.h>
12 #import "QMUIKit.h" 12 #import "QMUIKit.h"
  13 +#import "SGQRCode.h"//二维码库
13 14
14 -@interface CNLiveGroupQrCodeView ()  
15 -@property (nonatomic, strong) UIImageView *bgView;  
16 -@property (nonatomic, strong) UIButton *witness; 15 +//#import "SGQRCodeGenerateManager.h"
  16 +//#import "CNLiveGroupAvatorManager.h"
17 17
18 -@property (nonatomic, strong) UIImageView *header;  
19 -@property (nonatomic, strong) UILabel *name;  
20 -@property (nonatomic, strong) UILabel *certification;  
21 -@property (nonatomic, strong) UILabel *address;  
22 -@property (nonatomic, strong) UIButton *sign; 18 +@interface CNLiveGroupQrCodeView()
  19 +@property (nonatomic, strong) UIImageView *groupHead;
  20 +@property (nonatomic, strong) UILabel *groupName;
  21 +@property (nonatomic, strong) UIImageView *qrcode;
  22 +@property (nonatomic, strong) UILabel *desc;
23 23
24 @end 24 @end
25 -  
26 @implementation CNLiveGroupQrCodeView 25 @implementation CNLiveGroupQrCodeView
27 -static const NSInteger margin = 20; 26 +static const NSInteger margin = 15;
28 27
29 -- (instancetype)initWithFrame:(CGRect)frame{  
30 - self = [super initWithFrame:frame];  
31 - if(self){  
32 - self.userInteractionEnabled = YES;  
33 - self.backgroundColor = [UIColor colorWithRed:244.0/255.0 green:244.0/255.0 blue:244.0/255.0 alpha:1.0];  
34 - [self createSubViews]; 28 +- (instancetype)initWithFrame:(CGRect)frame {
  29 + if (self = [super initWithFrame:frame]) {
  30 + self.backgroundColor = [UIColor whiteColor];
  31 + [self createUI];
35 } 32 }
36 return self; 33 return self;
37 } 34 }
38 -// 实现方法  
39 -- (void)userInfoUpdateNotification:(NSNotification *)noti{  
40 - //使用userInfo处理消息  
41 -// NSDictionary *dic = [noti userInfo];  
42 -// XWUserInfoDataType type = [[dic objectForKey:@"type"] integerValue];  
43 -// if(type == XWUserInfoDataTypeHead){  
44 -// UIImage *info = [dic objectForKey:@"info"];  
45 -// _header.image = info;  
46 -//  
47 -// }else if(type == XWUserInfoDataTypeNickname){  
48 -// NSString *info = [dic objectForKey:@"info"];  
49 -// _name.attributedText = [self createAttributedImageName:@"mine_code" string:info isFront:NO];  
50 -//  
51 -// }else if(type == XWUserInfoDataTypeAddress){  
52 -// NSString *info = [dic objectForKey:@"info"];  
53 -// _address.attributedText = [self createAttributedImageName:@"mine_location" string:info isFront:YES];  
54 -//  
55 -// }  
56 -}  
57 -  
58 -- (void)dealloc {  
59 - NSLog(@"CNLiveGroupQrCodeView -- dealloc");  
60 -// [XWUserInfoNotification removeObserver:self];  
61 -  
62 -}  
63 -  
64 -- (void)createSubViews {  
65 - [self addSubview:self.bgView];  
66 - [self addSubview:self.witness];  
67 -  
68 - [self addSubview:self.header];  
69 - [self addSubview:self.name];  
70 - [self addSubview:self.certification];  
71 - [self addSubview:self.address];  
72 - [self addSubview:self.sign];  
73 35
74 -}  
75 -  
76 -- (void)layoutSubviews{  
77 - [super layoutSubviews];  
78 - [_witness mas_remakeConstraints:^(MASConstraintMaker *make) {  
79 - make.left.equalTo(self.mas_left).with.offset(1.5*margin);  
80 - make.right.equalTo(self.mas_right).with.offset(-1.5*margin);  
81 - make.width.height.offset(60);  
82 - make.bottom.equalTo(self.mas_bottom).with.offset(-0.5*margin);  
83 - 36 +#pragma mark - UI
  37 +- (void)createUI{
  38 + [self addSubview:self.groupHead];
  39 + [self.groupHead mas_makeConstraints:^(MASConstraintMaker *make) {
  40 + make.left.mas_equalTo(self).mas_offset(margin);
  41 + make.top.mas_equalTo(self).mas_offset(margin);
  42 + make.width.mas_equalTo(36);
  43 + make.height.mas_equalTo(36);
84 }]; 44 }];
85 45
86 - [_bgView mas_remakeConstraints:^(MASConstraintMaker *make) {  
87 - make.left.equalTo(self.mas_left).with.offset(0);  
88 - make.right.equalTo(self.mas_right).with.offset(-0);  
89 - make.top.equalTo(self.mas_top).with.offset(0);  
90 - make.bottom.equalTo(self.witness.mas_centerY).with.offset(0.5*margin);  
91 -  
92 - }];  
93 -  
94 - [_header mas_remakeConstraints:^(MASConstraintMaker *make) {  
95 - make.left.equalTo(self.mas_left).with.offset(margin);  
96 - make.centerY.equalTo(self.bgView.mas_centerY).with.offset(0);  
97 - make.width.height.offset(60); 46 + [self addSubview:self.groupName];
  47 + [self.groupName mas_makeConstraints:^(MASConstraintMaker *make) {
  48 + make.left.mas_equalTo(self.groupHead.mas_right).mas_offset(margin);
  49 + make.right.mas_equalTo(self.mas_right).mas_offset(-margin);
  50 + make.top.mas_equalTo(self.groupHead.mas_top);
  51 + make.height.mas_equalTo(self.groupHead.mas_height);
98 52
99 }]; 53 }];
100 54
101 - [_certification mas_remakeConstraints:^(MASConstraintMaker *make) {  
102 - make.centerY.equalTo(self.header.mas_centerY);  
103 - make.left.equalTo(self.header.mas_right).with.offset(margin/2.0);  
104 - make.height.offset(35);  
105 -  
106 - }];  
107 -  
108 - [_name mas_remakeConstraints:^(MASConstraintMaker *make) {  
109 - make.bottom.equalTo(self.certification.mas_top);  
110 - make.left.equalTo(self.certification.mas_left);  
111 - make.right.equalTo(self.bgView.mas_right).with.offset(-margin);  
112 - make.height.equalTo(self.certification.mas_height);  
113 - 55 + [self addSubview:self.qrcode];
  56 + [self.qrcode mas_makeConstraints:^(MASConstraintMaker *make) {
  57 + make.centerX.mas_equalTo(self.mas_centerX);
  58 + make.top.mas_equalTo(self.groupName.mas_bottom).mas_offset(margin);
  59 + make.width.mas_equalTo(220.0);
  60 + make.height.mas_equalTo(220.0);
114 }]; 61 }];
115 62
116 - [_address mas_remakeConstraints:^(MASConstraintMaker *make) {  
117 - make.top.equalTo(self.certification.mas_bottom);  
118 - make.left.equalTo(self.name.mas_left);  
119 - make.right.equalTo(self.name.mas_right);  
120 - make.height.equalTo(self.name.mas_height);  
121 -  
122 - }]; 63 + [self addSubview:self.desc];
  64 + [self.desc mas_makeConstraints:^(MASConstraintMaker *make) {
  65 + make.left.mas_equalTo(self.mas_left).mas_offset(margin);
  66 + make.right.mas_equalTo(self.mas_right).mas_offset(-margin);
  67 + make.top.mas_equalTo(self.qrcode.mas_bottom).mas_offset(0);
  68 + make.bottom.mas_equalTo(self.mas_bottom).mas_offset(-0);
123 69
124 - [_sign mas_remakeConstraints:^(MASConstraintMaker *make) {  
125 - make.right.equalTo(self.mas_right).with.offset(0);  
126 - make.centerY.equalTo(self.header.mas_centerY).with.offset(0);  
127 - make.width.mas_equalTo(105);  
128 - make.height.mas_equalTo(32);  
129 -  
130 - }]; 70 + }];
131 } 71 }
132 /* 72 /*
133 - // Only override drawRect: if you perform custom drawing.  
134 - // An empty implementation adversely affects performance during animation.  
135 - - (void)drawRect:(CGRect)rect {  
136 - // Drawing code  
137 - }  
138 - */  
139 -#pragma mark - Private Methods  
140 -- (NSMutableAttributedString *)createAttributedImageName:(NSString *)imageName string:(NSString *)string isFront:(BOOL)isFront{  
141 - if(isFront){  
142 - string = [NSString stringWithFormat:@" %@",string];  
143 - }  
144 - // 1.创建一个富文本  
145 - NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:string];  
146 - // 修改富文本中的不同文字的样式  
147 -// [attri addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:NSMakeRange(0, string.length)];  
148 -// [attri addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:14] range:NSMakeRange(0, string.length)];  
149 - // 2.添加表情图片  
150 - NSTextAttachment *attch = [[NSTextAttachment alloc] init];  
151 - // 表情图片  
152 - UIImage *xw_image = [self xw_getImageName:imageName bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeView class]];  
153 - attch.image = xw_image;  
154 - if(isFront){  
155 - // 设置图片大小  
156 - attch.bounds = CGRectMake(0, -1.5, 10, 12);  
157 - // 创建带有图片的富文本  
158 - NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch];  
159 - [attri insertAttributedString:str atIndex:0];// 插入某个位置  
160 - }else{  
161 - // 设置图片大小  
162 - attch.bounds = CGRectMake(10, -2, 15, 15);  
163 - // 创建带有图片的富文本  
164 - NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch];  
165 - [attri insertAttributedString:str atIndex:string.length];// 插入某个位置  
166 -  
167 - }  
168 - return attri;  
169 -  
170 -}  
171 -- (NSMutableAttributedString *)createAttributedImages:(NSArray *)images {  
172 - // 1.创建一个富文本  
173 - NSMutableAttributedString *attri = [[NSMutableAttributedString alloc] initWithString:@""];  
174 - for(NSString *image in images){  
175 - // 2.添加表情图片  
176 - NSTextAttachment *attch = [[NSTextAttachment alloc] init];  
177 - // 表情图片  
178 - UIImage *xw_image = [self xw_getImageName:image bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeView class]];  
179 - attch.image = xw_image;  
180 - // 创建带有图片的富文本  
181 - NSAttributedString *str = [NSAttributedString attributedStringWithAttachment:attch];  
182 - NSAttributedString *space = [[NSAttributedString alloc]initWithString:@" "]; 73 +// Only override drawRect: if you perform custom drawing.
  74 +// An empty implementation adversely affects performance during animation.
  75 +- (void)drawRect:(CGRect)rect {
  76 + // Drawing code
  77 +}
  78 +*/
  79 +
  80 +#pragma mark - Setter
  81 +//- (void)setGroup:(IMAGroup *)group{
  82 +// _group = group;
  83 +// if(group.avatorIcon){
  84 +// _groupHead.image = group.avatorIcon;
  85 +// }else{
  86 +// [_groupHead setImageWithGroupId:group.groupInfo.groupId];
  87 +//
  88 +// }
  89 +// _groupName.text = group.groupInfo.groupName;
  90 +// _qrcode.image = [SGQRCodeObtain generateWithLogoQRCodeData:group.groupInfo.groupId logoImageName:nil logoScaleToSuperView:0.2];
  91 +//
  92 +//}
183 93
184 - [attri insertAttributedString:space atIndex:0];  
185 - [attri insertAttributedString:str atIndex:0];// 插入某个位置 94 +#pragma mark - Getter
  95 +- (UIImageView *)groupHead {
  96 + if (!_groupHead) {
  97 + _groupHead = [[UIImageView alloc] init];
  98 + _groupHead.backgroundColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
186 99
187 } 100 }
188 - return attri;  
189 - 101 + return _groupHead;
190 } 102 }
191 103
192 -#pragma mark - 懒加载  
193 -- (UIButton *)witness {  
194 - if (!_witness) {  
195 - _witness = [UIButton buttonWithType:UIButtonTypeCustom];  
196 - UIImage *xw_image = [self xw_getImageName:@"mine_observer" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeView class]];  
197 - _witness.imageView.contentMode = UIViewContentModeScaleAspectFit;  
198 - [_witness setImage:xw_image forState:UIControlStateNormal];  
199 - _witness.adjustsImageWhenHighlighted = NO;  
200 - [_witness addTarget:self action:@selector(witnessDidClicked:) forControlEvents:UIControlEventTouchUpInside]; 104 +- (UILabel *)groupName {
  105 + if (!_groupName) {
  106 + _groupName = [[UILabel alloc] init];
  107 + _groupName.textColor = [UIColor colorWithRed:51/255.0 green:51/255.0 blue:51/255.0 alpha:1.0];
  108 + _groupName.font = UIFontMake(15);
  109 + _groupName.numberOfLines = 1;
  110 + _groupName.text = @"张晓文";
201 } 111 }
202 - return _witness;  
203 -}  
204 -- (UIImageView *)bgView {  
205 - if (!_bgView) {  
206 - _bgView = [[UIImageView alloc] init];  
207 - _bgView.userInteractionEnabled = YES;  
208 - UIImage *xw_image = [self xw_getImageName:@"mine_bg" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeView class]];  
209 - _bgView.image = xw_image;  
210 - }  
211 - return _bgView;  
212 -}  
213 -- (UIImageView *)header {  
214 - if (!_header) {  
215 - _header = [[UIImageView alloc] init];  
216 - _header.userInteractionEnabled = YES;  
217 - _header.layer.masksToBounds = YES;  
218 - _header.layer.cornerRadius = 30;  
219 - UIImage *xw_image = [self xw_getImageName:@"default_avatar_y" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeView class]];  
220 - [_header sd_setImageWithURL:[NSURL URLWithString:@"头像"] placeholderImage:xw_image];  
221 - UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(headerTapDidClicked:)];  
222 - [_header addGestureRecognizer:tap];  
223 - }  
224 - return _header; 112 + return _groupName;
225 } 113 }
226 114
227 -- (UILabel *)name {  
228 - if (!_name) {  
229 - _name = [[UILabel alloc] init];  
230 - _name.userInteractionEnabled = YES;  
231 - _name.numberOfLines = 1;  
232 - _name.textColor = [UIColor whiteColor];  
233 - _name.font = [UIFont systemFontOfSize:16];  
234 - _name.attributedText = [self createAttributedImageName:@"mine_code" string:@"张晓文" isFront:NO];  
235 - UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(nameTapDidClicked:)];  
236 - [_name addGestureRecognizer:tap];  
237 -  
238 - }  
239 - return _name;  
240 -}  
241 -- (UILabel *)certification {  
242 - if (!_certification) {  
243 - _certification = [[UILabel alloc] init];  
244 - _certification.numberOfLines = 1;  
245 - _certification.textColor = [UIColor whiteColor];  
246 - _certification.font = [UIFont systemFontOfSize:16];  
247 - _certification.attributedText = [self createAttributedImages:@[@"mine_overbadge",@"mine_common", @"mine_wjj_certification"]];  
248 - }  
249 - return _certification;  
250 -}  
251 -- (UILabel *)address {  
252 - if (!_address) {  
253 - _address = [[UILabel alloc] init];  
254 - _address.numberOfLines = 1;  
255 - _address.textColor = [UIColor colorWithRed:140/255.0 green:140/255.0 blue:142/255.0 alpha:1.0];  
256 - _address.font = [UIFont systemFontOfSize:13];  
257 - _address.attributedText = [self createAttributedImageName:@"mine_location" string:@"北京海淀区花园桥" isFront:YES]; 115 +- (UIImageView *)qrcode {
  116 + if (!_qrcode) {
  117 + _qrcode = [[UIImageView alloc] init];
  118 + _qrcode.backgroundColor = [UIColor greenColor];
  119 + _qrcode.image = [SGQRCodeObtain generateQRCodeWithData:@"群组id" size:220.0 logoImage:nil ratio:0.2];
258 } 120 }
259 - return _address; 121 + return _qrcode;
260 } 122 }
261 -- (UIButton *)sign {  
262 - if (!_sign) {  
263 - _sign = [UIButton buttonWithType:UIButtonTypeCustom];  
264 - _sign.frame = CGRectMake(0, 0, 105, 32);  
265 - _sign.backgroundColor = [[UIColor whiteColor] colorWithAlphaComponent:0.2];  
266 - [_sign setTitle:@"签到赚积分" forState:UIControlStateNormal];  
267 - _sign.titleLabel.font = [UIFont systemFontOfSize:13.0];  
268 - [_sign setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];  
269 - UIImage *xw_image = [self xw_getImageName:@"sign_in_soccer" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveGroupQrCodeView class]];  
270 - [_sign setImage:xw_image forState:UIControlStateNormal];  
271 - [_sign addTarget:self action:@selector(signDidClicked:) forControlEvents:UIControlEventTouchUpInside];  
272 - UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_sign.layer.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(16, 16)];  
273 - CAShapeLayer *maskLayer = [CAShapeLayer layer];  
274 - maskLayer.frame = _sign.bounds;  
275 - maskLayer.path = maskPath.CGPath;  
276 - _sign.layer.mask = maskLayer;  
277 - }  
278 - return _sign;  
279 -}  
280 -  
281 -#pragma mark - 响应方法  
282 -- (void)headerTapDidClicked:(UITapGestureRecognizer *)tap{  
283 123
284 - 124 +- (UILabel *)desc {
  125 + if (!_desc) {
  126 + _desc = [[UILabel alloc] init];
  127 + _desc.textColor = [UIColor colorWithRed:153/255.0 green:153/255.0 blue:153/255.0 alpha:1.0];
  128 + _desc.font = UIFontMake(15);
  129 + _desc.numberOfLines = 1;
  130 + _desc.text = @"用“网家家”扫描二维码,加入该群";
  131 + _desc.textAlignment = NSTextAlignmentCenter;
  132 + }
  133 + return _desc;
285 } 134 }
286 135
287 /** 136 /**
CNLiveQrCodeModule/Classes/View/CNLiveQrCodeNavigationBar.h
@@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN @@ -21,7 +21,7 @@ NS_ASSUME_NONNULL_BEGIN
21 @property (nonatomic, strong) UIView *navView; 21 @property (nonatomic, strong) UIView *navView;
22 @property (nonatomic, strong) UIButton *left; 22 @property (nonatomic, strong) UIButton *left;
23 @property (nonatomic, strong) UILabel *title; 23 @property (nonatomic, strong) UILabel *title;
24 -@property (nonatomic, strong) UIButton *right; 24 +@property (nonatomic, strong, nullable) UIButton *right;
25 25
26 @end 26 @end
27 27
CNLiveQrCodeModule/Classes/View/CNLiveQrCodeNavigationBar.m
@@ -57,6 +57,7 @@ static const NSInteger margin = 15; @@ -57,6 +57,7 @@ static const NSInteger margin = 15;
57 - (UIButton *)left { 57 - (UIButton *)left {
58 if (!_left) { 58 if (!_left) {
59 _left= [UIButton buttonWithType:UIButtonTypeSystem]; 59 _left= [UIButton buttonWithType:UIButtonTypeSystem];
  60 + _left.adjustsImageWhenHighlighted = NO;
60 _left.frame = CGRectMake(margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight); 61 _left.frame = CGRectMake(margin, StatusBarHeight, NavigationBarHeight, NavigationBarHeight);
61 UIImage *image = [self xw_getImageName:@"mine_back_white_b" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveQrCodeNavigationBar class]]; 62 UIImage *image = [self xw_getImageName:@"mine_back_white_b" bundleName:@"CNLiveQrCodeModule" targetClass:[CNLiveQrCodeNavigationBar class]];
62 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal]; 63 [_left setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
CNLiveQrCodeModule/Classes/View/CNLiveWebView.h 0 → 100755
  1 +//
  2 +// CNLiveWebView.h
  3 +// CNLiveQrCodeModule
  4 +//
  5 +// Created by 153993236@qq.com on 11/12/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +// CNLiveWebView 使用注意点:
  9 +// 如果 self.navigationController.navigationBar.translucent = NO;或者导航栏不存在; 那么 XWWebView 的 isNavigationBarOrTranslucent属性 必须设置 NO)
  10 +
  11 +#import <UIKit/UIKit.h>
  12 +@class CNLiveWebView;
  13 +
  14 +@protocol CNLiveWebViewDelegate <NSObject>
  15 +@optional
  16 +/** 页面开始加载时调用 */
  17 +- (void)webViewDidStartLoad:(CNLiveWebView *)webView;
  18 +/** 内容开始返回时调用 */
  19 +- (void)webView:(CNLiveWebView *)webView didCommitWithURL:(NSURL *)url;
  20 +/** 页面加载失败时调用 */
  21 +- (void)webView:(CNLiveWebView *)webView didFinishLoadWithURL:(NSURL *)url;
  22 +/** 页面加载完成之后调用 */
  23 +- (void)webView:(CNLiveWebView *)webView didFailLoadWithError:(NSError *)error;
  24 +@end
  25 +
  26 +@interface CNLiveWebView : UIView
  27 +/** XWDelegate */
  28 +@property (nonatomic, weak) id<CNLiveWebViewDelegate> delegate;
  29 +/** 进度条颜色(默认蓝色) */
  30 +@property (nonatomic, strong) UIColor *progressViewColor;
  31 +/** 导航栏标题 */
  32 +@property (nonatomic, copy) NSString *navigationItemTitle;
  33 +/** 导航栏存在且有穿透效果(默认导航栏存在且有穿透效果) */
  34 +@property (nonatomic, assign) BOOL isNavigationBarOrTranslucent;
  35 +
  36 +/** 类方法创建 XWWebView */
  37 ++ (instancetype)webViewWithFrame:(CGRect)frame;
  38 +/** 加载 web */
  39 +- (void)loadRequest:(NSURLRequest *)request;
  40 +/** 加载 HTML */
  41 +- (void)loadHTMLString:(NSString *)HTMLString;
  42 +/** 刷新数据 */
  43 +- (void)reloadData;
  44 +
  45 +@end
CNLiveQrCodeModule/Classes/View/CNLiveWebView.m 0 → 100755
  1 +//
  2 +// CNLiveWebView.m
  3 +// CNLiveQrCodeModule
  4 +//
  5 +// Created by 153993236@qq.com on 11/12/2019.
  6 +// Copyright (c) 2019 153993236@qq.com. All rights reserved.
  7 +//
  8 +
  9 +#import "CNLiveWebView.h"
  10 +#import <WebKit/WebKit.h>
  11 +#import "QMUIKit.h"
  12 +
  13 +@interface CNLiveWebView () <WKNavigationDelegate, WKUIDelegate>
  14 +// WKWebView
  15 +@property (nonatomic, strong) WKWebView *wkWebView;
  16 +// 进度条
  17 +@property (nonatomic, strong) UIProgressView *progressView;
  18 +
  19 +@end
  20 +
  21 +@implementation CNLiveWebView
  22 +
  23 +static CGFloat const progressViewHeight = 2;
  24 +
  25 +- (instancetype)initWithFrame:(CGRect)frame {
  26 + if (self = [super initWithFrame:frame]) {
  27 + [self addSubview:self.wkWebView];
  28 + [self addSubview:self.progressView];
  29 + }
  30 + return self;
  31 +}
  32 +
  33 ++ (instancetype)webViewWithFrame:(CGRect)frame {
  34 + return [[self alloc] initWithFrame:frame];
  35 +}
  36 +
  37 +- (WKWebView *)wkWebView {
  38 + if (!_wkWebView) {
  39 + _wkWebView = [[WKWebView alloc] initWithFrame:self.bounds];
  40 + _wkWebView.navigationDelegate = self;
  41 + _wkWebView.UIDelegate = self;
  42 + // KVO
  43 + [self.wkWebView addObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress)) options:0 context:nil];
  44 + }
  45 + return _wkWebView;
  46 +}
  47 +
  48 +- (UIProgressView *)progressView {
  49 + if (!_progressView) {
  50 + _progressView = [[UIProgressView alloc] initWithProgressViewStyle:UIProgressViewStyleDefault];
  51 + _progressView.trackTintColor = [UIColor clearColor];
  52 + // 高度默认有导航栏且有穿透效果
  53 + _progressView.frame = CGRectMake(0, NavigationContentTop, self.frame.size.width, progressViewHeight);
  54 + // 设置进度条颜色
  55 + _progressView.tintColor = [UIColor greenColor];
  56 + }
  57 + return _progressView;
  58 +}
  59 +
  60 +- (void)setProgressViewColor:(UIColor *)progressViewColor {
  61 + _progressViewColor = progressViewColor;
  62 +
  63 + if (progressViewColor) {
  64 + _progressView.tintColor = progressViewColor;
  65 + }
  66 +}
  67 +
  68 +- (void)setIsNavigationBarOrTranslucent:(BOOL)isNavigationBarOrTranslucent {
  69 + _isNavigationBarOrTranslucent = isNavigationBarOrTranslucent;
  70 +
  71 + if (isNavigationBarOrTranslucent == YES) { // 导航栏存在且有穿透效果
  72 + _progressView.frame = CGRectMake(0, NavigationContentTop, self.frame.size.width, progressViewHeight);
  73 + } else { // 导航栏不存在或者没有有穿透效果
  74 + _progressView.frame = CGRectMake(0, 0, self.frame.size.width, progressViewHeight);
  75 + }
  76 +}
  77 +/// KVO
  78 +- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSKeyValueChangeKey,id> *)change context:(void *)context {
  79 + if ([keyPath isEqualToString:NSStringFromSelector(@selector(estimatedProgress))] && object == self.wkWebView) {
  80 + self.progressView.alpha = 1.0;
  81 + BOOL animated = self.wkWebView.estimatedProgress > self.progressView.progress;
  82 + [self.progressView setProgress:self.wkWebView.estimatedProgress animated:animated];
  83 + if(self.wkWebView.estimatedProgress >= 0.97) {
  84 + [UIView animateWithDuration:0.1 delay:0.3 options:UIViewAnimationOptionCurveEaseOut animations:^{
  85 + self.progressView.alpha = 0.0;
  86 + } completion:^(BOOL finished) {
  87 + [self.progressView setProgress:0.0 animated:NO];
  88 + }];
  89 + }
  90 + } else {
  91 + [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
  92 + }
  93 +}
  94 +
  95 +#pragma mark - 加载的状态回调(WKNavigationDelegate)
  96 +/// 页面开始加载时调用
  97 +- (void)webView:(WKWebView *)webView didStartProvisionalNavigation:(WKNavigation *)navigation {
  98 + if (self.delegate && [self.delegate respondsToSelector:@selector(webViewDidStartLoad:)]) {
  99 + [self.delegate webViewDidStartLoad:self];
  100 + }
  101 +}
  102 +/// 当内容开始返回时调用
  103 +- (void)webView:(WKWebView *)webView didCommitNavigation:(WKNavigation *)navigation {
  104 + if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didCommitWithURL:)]) {
  105 + [self.delegate webView:self didCommitWithURL:self.wkWebView.URL];
  106 + }
  107 +
  108 + self.navigationItemTitle = self.wkWebView.title;
  109 +}
  110 +/// 页面加载完成之后调用
  111 +- (void)webView:(WKWebView *)webView didFinishNavigation:(WKNavigation *)navigation {
  112 + self.navigationItemTitle = self.wkWebView.title;
  113 + if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didFinishLoadWithURL:)]) {
  114 + [self.delegate webView:self didFinishLoadWithURL:self.wkWebView.URL];
  115 + }
  116 +
  117 + self.progressView.alpha = 0.0;
  118 +}
  119 +/// 页面加载失败时调用
  120 +- (void)webView:(WKWebView *)webView didFailNavigation:(WKNavigation *)navigation withError:(NSError *)error {
  121 + if (self.delegate && [self.delegate respondsToSelector:@selector(webView:didFailLoadWithError:)]) {
  122 + [self.delegate webView:self didFailLoadWithError:error];
  123 + }
  124 +
  125 + self.progressView.alpha = 0.0;
  126 +}
  127 +/// 加载 web
  128 +- (void)loadRequest:(NSURLRequest *)request {
  129 + [self.wkWebView loadRequest:request];
  130 +}
  131 +/// 加载 HTML
  132 +- (void)loadHTMLString:(NSString *)HTMLString {
  133 + [self.wkWebView loadHTMLString:HTMLString baseURL:nil];
  134 +}
  135 +/// 刷新数据
  136 +- (void)reloadData {
  137 + [self.wkWebView reload];
  138 +}
  139 +/// dealloc
  140 +- (void)dealloc {
  141 + [self.wkWebView removeObserver:self forKeyPath:NSStringFromSelector(@selector(estimatedProgress))];
  142 +}
  143 +
  144 +
  145 +@end
Example/CNLiveQrCodeModule/CNLIVEAppDelegate.m
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 #import "CNLIVEAppDelegate.h" 9 #import "CNLIVEAppDelegate.h"
10 #import "CNLiveMyQrCodeController.h" 10 #import "CNLiveMyQrCodeController.h"
11 #import "CNLiveScanQrCodeController.h" 11 #import "CNLiveScanQrCodeController.h"
  12 +#import "CNLiveGroupQrCodeController.h"
  13 +#import "CNLiveScanResultController.h"
12 14
13 @implementation CNLIVEAppDelegate 15 @implementation CNLIVEAppDelegate
14 16
@@ -18,8 +20,8 @@ @@ -18,8 +20,8 @@
18 20
19 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; 21 self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
20 22
21 - CNLiveScanQrCodeController *vc = [[CNLiveScanQrCodeController alloc] init];  
22 - 23 + CNLiveScanResultController *vc = [[CNLiveScanResultController alloc] init];
  24 + vc.jump_URL = @"http://www.baidu.com";
23 UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc]; 25 UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc];
24 26
25 self.window.rootViewController = nav;//设置根视图控制器 27 self.window.rootViewController = nav;//设置根视图控制器
Example/CNLiveQrCodeModule/CNLiveQrCodeModule-Info.plist
@@ -2,14 +2,11 @@ @@ -2,14 +2,11 @@
2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> 2 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3 <plist version="1.0"> 3 <plist version="1.0">
4 <dict> 4 <dict>
5 - <key>NSCameraUsageDescription</key>  
6 - <string>App需要您的同意,才能访问相机</string>  
7 - <key>NSMicrophoneUsageDescription</key>  
8 - <string>App需要您的同意,才能访问麦克风</string>  
9 - <key>NSPhotoLibraryAddUsageDescription</key>  
10 - <string>App需要您的同意,才能访问相册</string>  
11 - <key>NSPhotoLibraryUsageDescription</key>  
12 - <string>App需要您的同意,才能访问相册</string> 5 + <key>NSAppTransportSecurity</key>
  6 + <dict>
  7 + <key>NSAllowsArbitraryLoads</key>
  8 + <true/>
  9 + </dict>
13 <key>CFBundleDevelopmentRegion</key> 10 <key>CFBundleDevelopmentRegion</key>
14 <string>en</string> 11 <string>en</string>
15 <key>CFBundleDisplayName</key> 12 <key>CFBundleDisplayName</key>
@@ -32,6 +29,14 @@ @@ -32,6 +29,14 @@
32 <string>1.0</string> 29 <string>1.0</string>
33 <key>LSRequiresIPhoneOS</key> 30 <key>LSRequiresIPhoneOS</key>
34 <true/> 31 <true/>
  32 + <key>NSCameraUsageDescription</key>
  33 + <string>App需要您的同意,才能访问相机</string>
  34 + <key>NSMicrophoneUsageDescription</key>
  35 + <string>App需要您的同意,才能访问麦克风</string>
  36 + <key>NSPhotoLibraryAddUsageDescription</key>
  37 + <string>App需要您的同意,才能访问相册</string>
  38 + <key>NSPhotoLibraryUsageDescription</key>
  39 + <string>App需要您的同意,才能访问相册</string>
35 <key>UILaunchStoryboardName</key> 40 <key>UILaunchStoryboardName</key>
36 <string>LaunchScreen</string> 41 <string>LaunchScreen</string>
37 <key>UIMainStoryboardFile</key> 42 <key>UIMainStoryboardFile</key>
@@ -43,8 +48,6 @@ @@ -43,8 +48,6 @@
43 <key>UISupportedInterfaceOrientations</key> 48 <key>UISupportedInterfaceOrientations</key>
44 <array> 49 <array>
45 <string>UIInterfaceOrientationPortrait</string> 50 <string>UIInterfaceOrientationPortrait</string>
46 - <string>UIInterfaceOrientationLandscapeLeft</string>  
47 - <string>UIInterfaceOrientationLandscapeRight</string>  
48 </array> 51 </array>
49 <key>UISupportedInterfaceOrientations~ipad</key> 52 <key>UISupportedInterfaceOrientations~ipad</key>
50 <array> 53 <array>