Skip to content

Commit a436e4d

Browse files
committed
Fixed iOS 11 assertion failure
1 parent 990a3dc commit a436e4d

File tree

3 files changed

+16
-7
lines changed

3 files changed

+16
-7
lines changed

TOPasscodeViewController/Views/Main/TOPasscodeView.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -418,11 +418,11 @@ - (void)applyThemeForStyle:(TOPasscodeViewStyle)style
418418
if (isTranslucent) {
419419
UIBlurEffect *blurEffect = [self blurEffectForStyle:style];
420420
UIVibrancyEffect *vibrancyEffect = [UIVibrancyEffect effectForBlurEffect:blurEffect];
421-
self.inputField.effect = vibrancyEffect;
421+
self.inputField.visualEffectView.effect = vibrancyEffect;
422422
self.keypadView.vibrancyEffect = vibrancyEffect;
423423
}
424424
else {
425-
self.inputField.effect = nil;
425+
self.inputField.visualEffectView.effect = nil;
426426
self.keypadView.vibrancyEffect = nil;
427427
}
428428

TOPasscodeViewController/Views/Shared/TOPasscodeInputField.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ typedef NS_ENUM(NSInteger, TOPasscodeInputFieldStyle) {
1919
TOPasscodeInputFieldStyleVariable // The passcode can be any arbitrary number of characters (Shows an empty rectangle)
2020
};
2121

22-
@interface TOPasscodeInputField : UIVisualEffectView <UIKeyInput>
22+
@interface TOPasscodeInputField : UIView <UIKeyInput>
23+
24+
/* The visual effects view used to control the vibrancy of the input field */
25+
@property (nonatomic, strong, readonly) UIVisualEffectView *visualEffectView;
2326

2427
/* The input style of this control */
2528
@property (nonatomic, assign) TOPasscodeInputFieldStyle style;

TOPasscodeViewController/Views/Shared/TOPasscodeInputField.m

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ @interface TOPasscodeInputField ()
2222
@property (nonatomic, strong, readwrite) TOPasscodeFixedInputView *fixedInputView;
2323
@property (nonatomic, strong, readwrite) TOPasscodeVariableInputView *variableInputView;
2424
@property (nonatomic, strong, readwrite) UIButton *submitButton;
25+
@property (nonatomic, strong, readwrite) UIVisualEffectView *visualEffectView;
2526

2627
@end
2728

@@ -55,6 +56,9 @@ - (void)setUp
5556
self.backgroundColor = [UIColor clearColor];
5657
_submitButtonSpacing = 4.0f;
5758
_submitButtonVerticalSpacing = 5.0f;
59+
60+
_visualEffectView = [[UIVisualEffectView alloc] initWithEffect:nil];
61+
[self addSubview:_visualEffectView];
5862
}
5963

6064
- (void)setUpForStyle:(TOPasscodeInputFieldStyle)style
@@ -67,11 +71,11 @@ - (void)setUpForStyle:(TOPasscodeInputFieldStyle)style
6771

6872
if (style == TOPasscodeInputFieldStyleVariable) {
6973
self.variableInputView = [[TOPasscodeVariableInputView alloc] init];
70-
[self.contentView addSubview:self.variableInputView];
74+
[self.visualEffectView.contentView addSubview:self.variableInputView];
7175
}
7276
else {
7377
self.fixedInputView = [[TOPasscodeFixedInputView alloc] init];
74-
[self.contentView addSubview:self.fixedInputView];
78+
[self.visualEffectView.contentView addSubview:self.fixedInputView];
7579
}
7680

7781
// Set the frame for the currently visible input view
@@ -98,6 +102,8 @@ - (void)layoutSubviews
98102
{
99103
[super layoutSubviews];
100104

105+
self.visualEffectView.frame = self.inputField.bounds;
106+
101107
if (!self.submitButton) { return; }
102108

103109
[self.submitButton sizeToFit];
@@ -368,15 +374,15 @@ - (void)setHorizontalLayout:(BOOL)horizontalLayout animated:(BOOL)animated durat
368374

369375
UIView *snapshotView = nil;
370376

371-
if (self.submitButton.hidden == NO && animated) {
377+
if (self.submitButton && self.submitButton.hidden == NO && animated) {
372378
snapshotView = [self.submitButton snapshotViewAfterScreenUpdates:NO];
373379
snapshotView.frame = self.submitButton.frame;
374380
[self addSubview:snapshotView];
375381
}
376382

377383
_horizontalLayout = horizontalLayout;
378384

379-
if (!animated) {
385+
if (!animated || !self.submitButton) {
380386
[self sizeToFit];
381387
[self setNeedsLayout];
382388
return;

0 commit comments

Comments
 (0)