Skip to content

Commit 2ed8498

Browse files
committed
Fixed iPad keyboard hiding
Previously there was no way to bring it back after dismissing it
1 parent 3176f82 commit 2ed8498

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 3.8.4
2+
* Fixed not being able to show the keyboard again after dismissing it on iPad (Closed [#171](https://github.com/rolandleth/LTHPasscodeViewController/issues/171)).
3+
14
# 3.8.3
25
* Added a check that the new passcode is different than the existing one (Closed [#170](https://github.com/rolandleth/LTHPasscodeViewController/issues/170)).
36
* Improved the handling of `isSimple`.

LTHPasscodeViewController/LTHPasscodeViewController.m

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,6 @@ - (void)viewDidLoad {
471471

472472
_passcodeTextField = [[UITextField alloc] initWithFrame: CGRectZero];
473473
_passcodeTextField.delegate = self;
474-
_passcodeTextField.secureTextEntry = YES;
475474
_passcodeTextField.translatesAutoresizingMaskIntoConstraints = NO;
476475

477476
[self.view setNeedsUpdateConstraints];
@@ -714,8 +713,9 @@ - (UITextField *)_makeDigitField{
714713
field.text = _passcodeCharacter;
715714
field.textColor = _passcodeTextColor;
716715
field.font = _passcodeFont;
716+
field.delegate = self;
717717
field.secureTextEntry = NO;
718-
field.userInteractionEnabled = NO;
718+
field.tintColor = [UIColor clearColor];
719719
field.translatesAutoresizingMaskIntoConstraints = NO;
720720
[field setBorderStyle:UITextBorderStyleNone];
721721
return field;
@@ -749,8 +749,11 @@ - (void)updateViewConstraints {
749749

750750
_complexPasscodeOverlayView.hidden = self.isSimple;
751751
_passcodeTextField.hidden = self.isSimple;
752-
_passcodeTextField.keyboardType =
753-
self.isSimple ? UIKeyboardTypeNumberPad : UIKeyboardTypeASCIICapable;
752+
// This would make the existing text to be cleared after dismissing
753+
// the keyboard, then focusing the text field again.
754+
// When simple, the text field only acts as a proxy and is hidden anyway.
755+
_passcodeTextField.secureTextEntry = !self.isSimple;
756+
_passcodeTextField.keyboardType = self.isSimple ? UIKeyboardTypeNumberPad : UIKeyboardTypeASCIICapable;
754757
[_passcodeTextField reloadInputViews];
755758

756759
if (self.isSimple) {
@@ -1185,6 +1188,19 @@ - (void)_prepareForEnablingPasscode {
11851188

11861189

11871190
#pragma mark - UITextFieldDelegate
1191+
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
1192+
if (textField == _passcodeTextField) { return true; }
1193+
1194+
[_passcodeTextField becomeFirstResponder];
1195+
1196+
UITextPosition *end = _passcodeTextField.endOfDocument;
1197+
UITextRange *range = [_passcodeTextField textRangeFromPosition:end toPosition:end];
1198+
1199+
[_passcodeTextField setSelectedTextRange:range];
1200+
1201+
return false;
1202+
}
1203+
11881204
- (BOOL)textFieldShouldEndEditing:(UITextField *)textField {
11891205
if ((!_displayedAsLockScreen && !_displayedAsModal) || (_isUsingTouchID || !_useFallbackPasscode)) {
11901206
return YES;

0 commit comments

Comments
 (0)