CNLiveLoginController.m
6.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
//
// CNLiveLoginController.m
// CNLiveLoginModule
//
// Created by 153993236@qq.com on 11/12/2019.
// Copyright (c) 2019 153993236@qq.com. All rights reserved.
//
#import "CNLiveLoginController.h"
#import "MJExtension.h"
#import "QMUIKit.h"
#import "YYKit.h"
#import "CNLiveUserAgreementManager.h"
#import "CNLiveCategory.h"
#import "CNLiveLoginView.h"
#import "CNLiveThreeLoginView.h"
#import "CNLiveBindingTelController.h"//绑定手机号
#import "CNLiveCompleteInfoController.h"//修改昵称
@interface CNLiveLoginController()<CNLiveLoginViewDelegate, CNLiveThreeLoginViewDelegate>
@property (nonatomic, weak) CNLiveLoginView *loginView;
@property (nonatomic, weak) CNLiveThreeLoginView *threeLoginView;
@property (nonatomic, weak) YYLabel *protocol;
@property (nonatomic, strong) UIButton *close;
@end
@implementation CNLiveLoginController
#pragma mark - 生命周期
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
self.navigationController.navigationBarHidden = YES;
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.automaticallyAdjustsScrollViewInsets = NO;
self.view.backgroundColor = [UIColor whiteColor];
[self createUI];
}
- (void)createUI{
[self.view addSubview:self.close];
CNLiveLoginView *loginView = [[CNLiveLoginView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH/8.0, NavigationContentTop+20, SCREEN_WIDTH*3/4.0, 380)];
loginView.delegate = self;
[self.view addSubview:loginView];
self.loginView = loginView;
YYLabel *protocol = [[YYLabel alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT-30-SafeAreaInsetsConstantForDeviceWithNotch.bottom, SCREEN_WIDTH, 30)];
protocol.textAlignment = NSTextAlignmentCenter;
protocol.textColor = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
protocol.font = [UIFont systemFontOfSize:14.0];
NSMutableAttributedString *text = [[NSMutableAttributedString alloc] initWithString:@"登录即代表阅读并同意《用户协议》及《隐私政策》"];
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentCenter;//对齐方式
[text addAttribute:NSParagraphStyleAttributeName value:style range:NSMakeRange(0, text.length)];
text.color = [UIColor colorWithRed:173/255.0 green:173/255.0 blue:173/255.0 alpha:1.0];
text.font = [UIFont systemFontOfSize:14.0];
__weak typeof(self) weakSelf = self;
[text setTextHighlightRange:NSMakeRange(11, 4) color:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
[weakSelf.view endEditing:YES];
[CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementUser];
}];
[text setTextHighlightRange:NSMakeRange(text.length-5, 4) color:[UIColor colorWithRed:35/255.0 green:212/255.0 blue:30/255.0 alpha:1.0] backgroundColor:[UIColor clearColor] tapAction:^(UIView * _Nonnull containerView, NSAttributedString * _Nonnull text, NSRange range, CGRect rect) {
[weakSelf.view endEditing:YES];
[CNLiveUserAgreementManager jumpToAgreementH5WithType:CNLiveUserAgreementPrivacy];
}];
protocol.attributedText = text;
[self.view addSubview:protocol];
self.protocol = protocol;
CNLiveThreeLoginView *threeLoginView = [[CNLiveThreeLoginView alloc] initWithFrame:CGRectMake(loginView.left, SCREEN_HEIGHT-30-SafeAreaInsetsConstantForDeviceWithNotch.bottom-100-10, loginView.width, 100)];
threeLoginView.delegate = self;
[self.view addSubview:threeLoginView];
self.threeLoginView = threeLoginView;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self.view endEditing:YES];
}
#pragma mark - CNLiveLoginViewDelegate
- (void)loginSuccess:(CNLiveLoginView *)view isNewUser:(BOOL)isNewUser result:(id _Nonnull)result{
if (isNewUser) {
// 新用户 -> 设置昵称和头像
CNLiveCompleteInfoController *vc = [[CNLiveCompleteInfoController alloc]init];
vc.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:vc animated:YES];
}else{
// 老用户 -> home
// [XWAlertView alertSucceedViewWithTextMessage:@"登录成功" view:self.view block:^{
// // 通知
// [XWLoginNotification postUserLoginNotification:result];
// }];
}
}
#pragma mark - CNLiveThreeLoginViewDelegate
- (void)clickedButton:(CNLiveThreeLoginView *)view type:(CNLiveThreeLoginType)type{
// 1.请求三方平台
// 2.绑定手机号
[self jumpToBindingTelController:type];
}
- (void)jumpToBindingTelController:(CNLiveThreeLoginType)type{
CNLiveBindingTelController *vc = [[CNLiveBindingTelController alloc]initWithType:type];
[self.navigationController pushViewController:vc animated:YES];
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
#pragma mark - 响应事件
- (void)closeDidSelected:(UIButton *)btn{
if (self.navigationController.topViewController == self) {
[self.navigationController popViewControllerAnimated:YES];
}else{
[self dismissViewControllerAnimated:YES completion:nil];
}
}
#pragma mark - 懒加载
- (UIButton *)close{
if (!_close) {
_close = [UIButton buttonWithType:UIButtonTypeCustom];
_close.frame = CGRectMake(SCREEN_WIDTH-44-10, StatusBarHeight, 44, 44);
_close.hidden = !self.isShowClose;
UIImage *image = [UIImage cn_getImageName:@"login_close" bundleName:@"CNLiveLoginModule" targetClass:[self class]];
[_close setImage:image forState:UIControlStateNormal];
[_close addTarget:self action:@selector(closeDidSelected:) forControlEvents:UIControlEventTouchUpInside];
_close.adjustsImageWhenHighlighted = NO;
}
return _close;
}
@end