Commit 215d3d0fd424269f3a71933eb6e476ebe82b5768
1 parent
6a62ef08
解决密码输入框键盘弹出问题
Showing
2 changed files
with
66 additions
and
25 deletions
CNLiveScioLive/Pages/Login/View/CNLiveLoginInputView.m
| ... | ... | @@ -35,7 +35,8 @@ |
| 35 | 35 | case CNLiveButtonTypeTextEntry: |
| 36 | 36 | { |
| 37 | 37 | _show.hidden = NO; |
| 38 | - _textField.secureTextEntry = YES; | |
| 38 | +// _textField.secureTextEntry = YES; | |
| 39 | + _textField.keyboardType = UIKeyboardTypeASCIICapable; | |
| 39 | 40 | // [_show setTitle:CustomStr(@"Show") forState:UIControlStateNormal]; |
| 40 | 41 | // [_show setTitle:CustomStr(@"Hide") forState:UIControlStateSelected]; |
| 41 | 42 | [_show setImage:[UIImage imageNamed:@"cnlive_show"] forState:UIControlStateNormal]; |
| ... | ... | @@ -181,7 +182,11 @@ |
| 181 | 182 | - (void)clickedShowBtn:(UIButton *)sender{ |
| 182 | 183 | //避免明文/密文切换后光标位置偏移 |
| 183 | 184 | self.textField.enabled = NO; // the first one; |
| 184 | - self.textField.secureTextEntry = sender.selected; | |
| 185 | + if (sender.selected == YES&&![self.textField.text isEqualToString:@""]) { | |
| 186 | + self.textField.secureTextEntry = sender.selected; | |
| 187 | + }else if (sender.selected == NO){ | |
| 188 | + self.textField.secureTextEntry = sender.selected; | |
| 189 | + } | |
| 185 | 190 | sender.selected = !sender.selected; |
| 186 | 191 | self.textField.enabled = YES; // the second one; |
| 187 | 192 | [self.textField becomeFirstResponder]; // the third one |
| ... | ... | @@ -227,11 +232,20 @@ |
| 227 | 232 | } |
| 228 | 233 | #pragma mark - UITextFieldDelegate |
| 229 | 234 | - (BOOL)textFieldShouldEndEditing:(UITextField *)textField{ |
| 235 | + if ([textField.text isEqualToString:@""]) { | |
| 236 | + textField.secureTextEntry = NO; | |
| 237 | + } | |
| 230 | 238 | return YES; |
| 231 | 239 | |
| 232 | 240 | } |
| 233 | -- (void)textFieldDidEndEditing:(UITextField *)textField{ | |
| 234 | - | |
| 241 | +-(BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string | |
| 242 | +{ | |
| 243 | + if (_type == CNLiveButtonTypeTextEntry) { | |
| 244 | + if (_show.selected == NO) { | |
| 245 | + textField.secureTextEntry = YES; | |
| 246 | + } | |
| 247 | + } | |
| 248 | + return YES; | |
| 235 | 249 | } |
| 236 | 250 | - (void)dealloc{ |
| 237 | 251 | [[NSNotificationCenter defaultCenter] removeObserver:self]; | ... | ... |
CNLiveScioLive/Pages/Register/Controller/CNLiveRegisterPhoneViewController.m
| ... | ... | @@ -47,8 +47,12 @@ |
| 47 | 47 | } |
| 48 | 48 | - (void)setUpSubControllers{ |
| 49 | 49 | |
| 50 | - _phone = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone" placeholder:CustomStr(@"PleaseFillInYourPhoneNumber") type:CNLiveButtonTypeNormal]; | |
| 51 | - [self.view addSubview:_phone]; | |
| 50 | + | |
| 51 | + [self.view addSubview:self.phone]; | |
| 52 | + [self.view addSubview:self.code]; | |
| 53 | + [self.view addSubview:self.pwd]; | |
| 54 | + [self.view addSubview:self.agreeButton]; | |
| 55 | + | |
| 52 | 56 | [_phone mas_makeConstraints:^(MASConstraintMaker *make) { |
| 53 | 57 | make.top.equalTo(self.view.mas_top).with.offset(15); |
| 54 | 58 | make.left.equalTo(self.view.mas_left).with.offset(0); |
| ... | ... | @@ -56,13 +60,6 @@ |
| 56 | 60 | make.height.offset(40); |
| 57 | 61 | |
| 58 | 62 | }]; |
| 59 | - | |
| 60 | - _code = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone_message" placeholder:CustomStr(@"PleaseFillInTheVerificationCodeReceivedByMobilePhone") type:CNLiveButtonTypeCode]; | |
| 61 | - __weak typeof(self) weakSelf = self; | |
| 62 | - _code.block = ^{ | |
| 63 | - [weakSelf getVerification]; | |
| 64 | - }; | |
| 65 | - [self.view addSubview:_code]; | |
| 66 | 63 | [_code mas_makeConstraints:^(MASConstraintMaker *make) { |
| 67 | 64 | make.top.equalTo(self->_phone.mas_bottom).with.offset(15); |
| 68 | 65 | make.left.equalTo(self.view.mas_left).with.offset(0); |
| ... | ... | @@ -70,9 +67,6 @@ |
| 70 | 67 | make.height.offset(40); |
| 71 | 68 | |
| 72 | 69 | }]; |
| 73 | - | |
| 74 | - _pwd = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_password" placeholder:CustomStr(@"PleaseEnterA6-16-bitPassword") type:CNLiveButtonTypeTextEntry]; | |
| 75 | - [self.view addSubview:_pwd]; | |
| 76 | 70 | [_pwd mas_makeConstraints:^(MASConstraintMaker *make) { |
| 77 | 71 | make.top.equalTo(self->_code.mas_bottom).with.offset(15); |
| 78 | 72 | make.left.equalTo(self.view.mas_left).with.offset(0); |
| ... | ... | @@ -81,14 +75,6 @@ |
| 81 | 75 | |
| 82 | 76 | }]; |
| 83 | 77 | |
| 84 | - | |
| 85 | - _agreeButton = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 86 | - _agreeButton.tag = 10000; | |
| 87 | - [_agreeButton addTarget:self action:@selector(clicekdButton:) forControlEvents:UIControlEventTouchUpInside]; | |
| 88 | - [_agreeButton setImage:[UIImage imageNamed:@"cnlive_login_check"] forState:UIControlStateNormal]; | |
| 89 | - [_agreeButton setImage:[UIImage imageNamed:@"cnlive_login_check out"] forState:UIControlStateSelected]; | |
| 90 | - | |
| 91 | - [self.view addSubview:_agreeButton]; | |
| 92 | 78 | [_agreeButton mas_makeConstraints:^(MASConstraintMaker *make) { |
| 93 | 79 | |
| 94 | 80 | make.top.equalTo(self->_pwd.mas_bottom).with.offset(15); |
| ... | ... | @@ -290,7 +276,48 @@ |
| 290 | 276 | |
| 291 | 277 | } |
| 292 | 278 | - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{ |
| 293 | - [self allResignFirstResponder]; | |
| 279 | + [self.view endEditing:YES]; | |
| 280 | + | |
| 281 | +} | |
| 282 | + | |
| 283 | +#pragma mark - GETTING | |
| 284 | +- (CNLiveLoginInputView *)phone | |
| 285 | +{ | |
| 286 | + if (!_phone) { | |
| 287 | + _phone = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone" placeholder:CustomStr(@"PleaseFillInYourPhoneNumber") type:CNLiveButtonTypeNormal]; | |
| 288 | + } | |
| 289 | + return _phone; | |
| 290 | +} | |
| 291 | + | |
| 292 | +- (CNLiveLoginInputView *)code | |
| 293 | +{ | |
| 294 | + if (!_code) { | |
| 295 | + _code = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_phone_message" placeholder:CustomStr(@"PleaseFillInTheVerificationCodeReceivedByMobilePhone") type:CNLiveButtonTypeCode]; | |
| 296 | + __weak typeof(self) weakSelf = self; | |
| 297 | + _code.block = ^{ | |
| 298 | + [weakSelf getVerification]; | |
| 299 | + }; | |
| 300 | + } | |
| 301 | + return _code; | |
| 302 | +} | |
| 294 | 303 | |
| 304 | +- (CNLiveLoginInputView *)pwd | |
| 305 | +{ | |
| 306 | + if (!_pwd) { | |
| 307 | + _pwd = [[CNLiveLoginInputView alloc] initWithPic:@"cnlive_password" placeholder:CustomStr(@"PleaseEnterA6-16-bitPassword") type:CNLiveButtonTypeTextEntry]; | |
| 308 | + } | |
| 309 | + return _pwd; | |
| 310 | +} | |
| 311 | + | |
| 312 | +-(UIButton *)agreeButton | |
| 313 | +{ | |
| 314 | + if (!_agreeButton) { | |
| 315 | + _agreeButton = [UIButton buttonWithType:UIButtonTypeCustom]; | |
| 316 | + _agreeButton.tag = 10000; | |
| 317 | + [_agreeButton addTarget:self action:@selector(clicekdButton:) forControlEvents:UIControlEventTouchUpInside]; | |
| 318 | + [_agreeButton setImage:[UIImage imageNamed:@"cnlive_login_check"] forState:UIControlStateNormal]; | |
| 319 | + [_agreeButton setImage:[UIImage imageNamed:@"cnlive_login_check out"] forState:UIControlStateSelected]; | |
| 320 | + } | |
| 321 | + return _agreeButton; | |
| 295 | 322 | } |
| 296 | 323 | @end | ... | ... |