Commit 7ebd2c8bd7bc9427e2481300bb67fd0b5656d0f3
1 parent
8306479e
no message
Showing
4 changed files
with
86 additions
and
66 deletions
CNLiveQrCodeModule/Classes/Controller/CNLiveMyQrCodeController.m
| @@ -16,8 +16,9 @@ | @@ -16,8 +16,9 @@ | ||
| 16 | 16 | ||
| 17 | #import "CNLiveQrCodeNavigationBar.h" | 17 | #import "CNLiveQrCodeNavigationBar.h" |
| 18 | #import "CNLiveMyQrCodeView.h" | 18 | #import "CNLiveMyQrCodeView.h" |
| 19 | +#import "CNLiveScanQrCodeController.h" | ||
| 19 | 20 | ||
| 20 | -@interface CNLiveMyQrCodeController ()<CNLiveQrCodeNavigationBarDelegate> | 21 | +@interface CNLiveMyQrCodeController ()<CNLiveQrCodeNavigationBarDelegate,QMUIAlertControllerDelegate> |
| 21 | @property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar; | 22 | @property (nonatomic, strong) CNLiveQrCodeNavigationBar *navigationBar; |
| 22 | @property (nonatomic, strong) UIImageView *bgView; | 23 | @property (nonatomic, strong) UIImageView *bgView; |
| 23 | @property (nonatomic, strong) CNLiveMyQrCodeView *qrCodeView; | 24 | @property (nonatomic, strong) CNLiveMyQrCodeView *qrCodeView; |
| @@ -57,17 +58,6 @@ static const CGFloat timeValue = 1.5; | @@ -57,17 +58,6 @@ static const CGFloat timeValue = 1.5; | ||
| 57 | 58 | ||
| 58 | } | 59 | } |
| 59 | 60 | ||
| 60 | -/** | ||
| 61 | - * 状态栏的颜色 | ||
| 62 | - * | ||
| 63 | - * @return UIStatusBarStyle | ||
| 64 | - * | ||
| 65 | - */ | ||
| 66 | -- (UIStatusBarStyle)preferredStatusBarStyle{ | ||
| 67 | - return UIStatusBarStyleLightContent; | ||
| 68 | - | ||
| 69 | -} | ||
| 70 | - | ||
| 71 | #pragma mark - 响应方法 | 61 | #pragma mark - 响应方法 |
| 72 | - (void)goBack { | 62 | - (void)goBack { |
| 73 | if (self.presentingViewController != nil) { | 63 | if (self.presentingViewController != nil) { |
| @@ -79,58 +69,6 @@ static const CGFloat timeValue = 1.5; | @@ -79,58 +69,6 @@ static const CGFloat timeValue = 1.5; | ||
| 79 | } | 69 | } |
| 80 | } | 70 | } |
| 81 | 71 | ||
| 82 | -- (void)rightButtonDidClicked:(UIButton *)btn { | ||
| 83 | - btn.userInteractionEnabled = NO; | ||
| 84 | - __weak typeof(self) weakSelf = self; | ||
| 85 | -// XWAlertController *alertController = [XWAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:XWAlertControllerStyleActionSheet]; | ||
| 86 | -// alertController.delegate = self; | ||
| 87 | -// alertController.needDialogBlur = NO; | ||
| 88 | -// XWAlertAction *action1 = [XWAlertAction actionWithTitle:@"保存图片" style:XWAlertActionStyleDefault handler:^(XWAlertAction * _Nonnull action) { | ||
| 89 | -// __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 90 | -// if(!strongSelf) return ; | ||
| 91 | -// [strongSelf getPHAuthorizationStatus:^{ | ||
| 92 | -// UIImage *image = [self.qrCodeView getImage]; | ||
| 93 | -// [strongSelf saveImage:image]; | ||
| 94 | -// }]; | ||
| 95 | -// btn.userInteractionEnabled = YES; | ||
| 96 | -// | ||
| 97 | -// }]; | ||
| 98 | -// XWAlertAction *action2 = [XWAlertAction actionWithTitle:@"扫描二维码" style:XWAlertActionStyleDefault handler:^(XWAlertAction * _Nonnull action) { | ||
| 99 | -// __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 100 | -// if(!strongSelf) return ; | ||
| 101 | -// if(strongSelf.isScanCode){ | ||
| 102 | -// [strongSelf.navigationController popViewControllerAnimated:YES]; | ||
| 103 | -// }else{ | ||
| 104 | -// XWScanQrCodeController *vc = [[XWScanQrCodeController alloc]init]; | ||
| 105 | -// vc.isMyCode = YES; | ||
| 106 | -// [strongSelf.navigationController pushViewController:vc animated:YES]; | ||
| 107 | -// } | ||
| 108 | -// btn.userInteractionEnabled = YES; | ||
| 109 | -// | ||
| 110 | -// }]; | ||
| 111 | -// XWAlertAction *action3 = [XWAlertAction actionWithTitle:@"重置二维码" style:XWAlertActionStyleDefault handler:^(XWAlertAction * _Nonnull action) { | ||
| 112 | -// __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 113 | -// if(!strongSelf) return ; | ||
| 114 | -// [strongSelf.qrCodeView generateQRCode:@"reset"]; | ||
| 115 | -// btn.userInteractionEnabled = YES; | ||
| 116 | -// | ||
| 117 | -// }]; | ||
| 118 | -// XWAlertAction *action4 = [XWAlertAction actionWithTitle:@"取消" style:XWAlertActionStyleCancel handler:^(XWAlertAction * _Nonnull action) { | ||
| 119 | -// btn.userInteractionEnabled = YES; | ||
| 120 | -// }]; | ||
| 121 | -// [alertController addAction:action1]; | ||
| 122 | -// [alertController addAction:action2]; | ||
| 123 | -// [alertController addAction:action3]; // 取消按钮一定排在最底部 | ||
| 124 | -// [alertController addAction:action4]; // 取消按钮一定排在最底部 | ||
| 125 | -// | ||
| 126 | -// [self presentViewController:alertController animated:YES completion:^{}]; | ||
| 127 | - | ||
| 128 | -} | ||
| 129 | -//// 已经dismiss | ||
| 130 | -//- (void)didDismissAlertController:(XWAlertController *)alertController{ | ||
| 131 | -// self.rightBtn.userInteractionEnabled = YES; | ||
| 132 | -//} | ||
| 133 | - | ||
| 134 | - (void)getPHAuthorizationStatus:(void (^)(void))block{ | 72 | - (void)getPHAuthorizationStatus:(void (^)(void))block{ |
| 135 | // 1.获取当前App的相册授权状态 | 73 | // 1.获取当前App的相册授权状态 |
| 136 | PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; | 74 | PHAuthorizationStatus authorizationStatus = [PHPhotoLibrary authorizationStatus]; |
| @@ -169,6 +107,10 @@ static const CGFloat timeValue = 1.5; | @@ -169,6 +107,10 @@ static const CGFloat timeValue = 1.5; | ||
| 169 | 107 | ||
| 170 | // 保存图片 | 108 | // 保存图片 |
| 171 | - (void)saveImage:(UIImage *)image{ | 109 | - (void)saveImage:(UIImage *)image{ |
| 110 | + if(!image){ | ||
| 111 | + [QMUITips showError:@"保存失败" inView:self.view hideAfterDelay:timeValue]; | ||
| 112 | + return; | ||
| 113 | + } | ||
| 172 | [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{ | 114 | [[PHPhotoLibrary sharedPhotoLibrary]performChanges:^{ |
| 173 | [PHAssetChangeRequest creationRequestForAssetFromImage:image]; | 115 | [PHAssetChangeRequest creationRequestForAssetFromImage:image]; |
| 174 | 116 | ||
| @@ -187,11 +129,86 @@ static const CGFloat timeValue = 1.5; | @@ -187,11 +129,86 @@ static const CGFloat timeValue = 1.5; | ||
| 187 | } | 129 | } |
| 188 | 130 | ||
| 189 | #pragma mark - 代理 | 131 | #pragma mark - 代理 |
| 132 | + | ||
| 133 | +/** | ||
| 134 | + * 状态栏的颜色 | ||
| 135 | + * | ||
| 136 | + * @return UIStatusBarStyle | ||
| 137 | + * | ||
| 138 | + */ | ||
| 139 | +- (UIStatusBarStyle)preferredStatusBarStyle{ | ||
| 140 | + return UIStatusBarStyleLightContent; | ||
| 141 | + | ||
| 142 | +} | ||
| 143 | + | ||
| 190 | - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ | 144 | - (void)navigationBar:(CNLiveQrCodeNavigationBar *)navigationBar actionEvents:(NSString *)actionEvents{ |
| 191 | if ([actionEvents isEqualToString:@"1"]) { | 145 | if ([actionEvents isEqualToString:@"1"]) { |
| 192 | [self goBack]; | 146 | [self goBack]; |
| 193 | } | 147 | } |
| 148 | + else if ([actionEvents isEqualToString:@"2"]){ | ||
| 149 | + self.navigationBar.right.userInteractionEnabled = NO; | ||
| 150 | + __weak typeof(self) weakSelf = self; | ||
| 151 | + QMUIAlertAction *action1 = [QMUIAlertAction actionWithTitle:@"保存图片" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | ||
| 152 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 153 | + if(!strongSelf) return ; | ||
| 154 | + [strongSelf getPHAuthorizationStatus:^{ | ||
| 155 | + UIImage *image = [self.qrCodeView getImage]; | ||
| 156 | + [strongSelf saveImage:image]; | ||
| 157 | + }]; | ||
| 158 | + self.navigationBar.right.userInteractionEnabled = YES; | ||
| 159 | + | ||
| 160 | + }]; | ||
| 161 | + QMUIAlertAction *action2 = [QMUIAlertAction actionWithTitle:@"扫描二维码" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | ||
| 162 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 163 | + if(!strongSelf) return ; | ||
| 164 | + if(strongSelf.isScanCode){ | ||
| 165 | + [strongSelf.navigationController popViewControllerAnimated:YES]; | ||
| 166 | + }else{ | ||
| 167 | + CNLiveScanQrCodeController *vc = [[CNLiveScanQrCodeController alloc]init]; | ||
| 168 | + vc.isMyCode = YES; | ||
| 169 | + [strongSelf.navigationController pushViewController:vc animated:YES]; | ||
| 170 | + } | ||
| 171 | + self.navigationBar.right.userInteractionEnabled = YES; | ||
| 172 | + }]; | ||
| 173 | + QMUIAlertAction *action3 = [QMUIAlertAction actionWithTitle:@"重置二维码" style:QMUIAlertActionStyleDefault handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | ||
| 174 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 175 | + if(!strongSelf) return ; | ||
| 176 | + [strongSelf.qrCodeView generateQRCode:@"reset"]; | ||
| 177 | + self.navigationBar.right.userInteractionEnabled = YES; | ||
| 178 | + | ||
| 179 | + }]; | ||
| 180 | + QMUIAlertAction *cancel = [QMUIAlertAction actionWithTitle:@"取消" style:QMUIAlertActionStyleCancel handler:^(__kindof QMUIAlertController *aAlertController, QMUIAlertAction *action) { | ||
| 181 | + __strong typeof(weakSelf) strongSelf = weakSelf; | ||
| 182 | + if(!strongSelf) return ; | ||
| 183 | + [strongSelf.qrCodeView generateQRCode:@"reset"]; | ||
| 184 | + self.navigationBar.right.userInteractionEnabled = YES; | ||
| 185 | + | ||
| 186 | + }]; | ||
| 187 | + | ||
| 188 | + QMUIAlertController *alertController = [QMUIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:QMUIAlertControllerStyleActionSheet]; | ||
| 189 | + alertController.delegate = self; | ||
| 190 | + [alertController addAction:action1]; | ||
| 191 | + [alertController addAction:action2]; | ||
| 192 | + [alertController addAction:action3]; | ||
| 193 | + [alertController addAction:cancel]; | ||
| 194 | + | ||
| 195 | + NSMutableDictionary *cancelTitleAttributs = [[NSMutableDictionary alloc] initWithDictionary:alertController.alertTitleAttributes]; | ||
| 196 | + | ||
| 197 | + cancelTitleAttributs[NSForegroundColorAttributeName] = [UIColor greenColor]; | ||
| 198 | + | ||
| 199 | + action1.buttonAttributes = cancelTitleAttributs; | ||
| 200 | + action2.buttonAttributes = cancelTitleAttributs; | ||
| 201 | + action3.buttonAttributes = cancelTitleAttributs; | ||
| 202 | + cancel.buttonAttributes = cancelTitleAttributs; | ||
| 203 | + | ||
| 204 | + [alertController showWithAnimated:YES]; | ||
| 205 | + } | ||
| 194 | } | 206 | } |
| 207 | +- (void)didHideAlertController:(QMUIAlertController *)alertController{ | ||
| 208 | + self.navigationBar.right.userInteractionEnabled = YES; | ||
| 209 | + | ||
| 210 | +} | ||
| 211 | + | ||
| 195 | #pragma mark - 懒加载 | 212 | #pragma mark - 懒加载 |
| 196 | - (UIImageView *)bgView{ | 213 | - (UIImageView *)bgView{ |
| 197 | if(!_bgView){ | 214 | if(!_bgView){ |
CNLiveQrCodeModule/Classes/View/CNLiveMyQrCodeView.h
CNLiveQrCodeModule/Classes/View/CNLiveMyQrCodeView.m
| @@ -24,6 +24,7 @@ | @@ -24,6 +24,7 @@ | ||
| 24 | 24 | ||
| 25 | @implementation CNLiveMyQrCodeView | 25 | @implementation CNLiveMyQrCodeView |
| 26 | static const NSInteger margin = 20; | 26 | static const NSInteger margin = 20; |
| 27 | +static const CGFloat timeValue = 1.5; | ||
| 27 | 28 | ||
| 28 | - (instancetype)initWithFrame:(CGRect)frame{ | 29 | - (instancetype)initWithFrame:(CGRect)frame{ |
| 29 | self = [super initWithFrame:frame]; | 30 | self = [super initWithFrame:frame]; |
Example/CNLiveQrCodeModule/CNLIVEAppDelegate.m
| @@ -20,8 +20,8 @@ | @@ -20,8 +20,8 @@ | ||
| 20 | 20 | ||
| 21 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; | 21 | self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds]; |
| 22 | 22 | ||
| 23 | - CNLiveScanResultController *vc = [[CNLiveScanResultController alloc] init]; | ||
| 24 | - vc.jump_URL = @"http://www.baidu.com"; | 23 | + CNLiveMyQrCodeController *vc = [[CNLiveMyQrCodeController alloc] init]; |
| 24 | +// vc.jump_URL = @"http://www.baidu.com"; | ||
| 25 | UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc]; | 25 | UINavigationController *nav = [[UINavigationController alloc]initWithRootViewController:vc]; |
| 26 | 26 | ||
| 27 | self.window.rootViewController = nav;//设置根视图控制器 | 27 | self.window.rootViewController = nav;//设置根视图控制器 |