@@ -17,6 +17,9 @@ @interface TOPasscodeViewController () <UIViewControllerTransitioningDelegate>
17
17
/* State */
18
18
@property (nonatomic , assign , readwrite ) TOPasscodeType passcodeType;
19
19
@property (nonatomic , assign ) CGFloat keyboardHeight;
20
+ @property (nonatomic , assign ) BOOL passcodeSuccess;
21
+ @property (nonatomic , readonly ) UIView *leftButton;
22
+ @property (nonatomic , readonly ) UIView *rightButton;
20
23
21
24
/* Views */
22
25
@property (nonatomic , strong , readwrite ) UIVisualEffectView *backgroundEffectView;
@@ -25,6 +28,7 @@ @interface TOPasscodeViewController () <UIViewControllerTransitioningDelegate>
25
28
@property (nonatomic , strong , readwrite ) UIButton *biometricButton;
26
29
@property (nonatomic , strong , readwrite ) UIButton *cancelButton;
27
30
31
+
28
32
@end
29
33
30
34
@implementation TOPasscodeViewController
@@ -323,18 +327,16 @@ - (void)verticalLayoutAccessoryButtonsForSize:(CGSize)size
323
327
CGFloat inset = self.passcodeView .keypadButtonInset ;
324
328
CGPoint point = (CGPoint){0 .0f , (self.view .bounds .size .height - self.keyboardHeight ) - verticalInset};
325
329
326
- UIButton *leftButton = self.leftAccessoryButton ? self.leftAccessoryButton : self.biometricButton ;
327
- if (leftButton) {
328
- [leftButton sizeToFit ];
330
+ if (self.leftButton ) {
331
+ [self .leftButton sizeToFit ];
329
332
point.x = self.passcodeView .frame .origin .x + inset;
330
- leftButton.center = point;
333
+ self. leftButton .center = point;
331
334
}
332
335
333
- UIButton *rightButton = self.rightAccessoryButton ? self.rightAccessoryButton : self.cancelButton ;
334
- if (rightButton) {
335
- [rightButton sizeToFit ];
336
+ if (self.rightButton ) {
337
+ [self .rightButton sizeToFit ];
336
338
point.x = CGRectGetMaxX (self.passcodeView .frame ) - inset;
337
- rightButton.center = point;
339
+ self. rightButton .center = point;
338
340
}
339
341
}
340
342
@@ -351,27 +353,24 @@ - (void)horizontalLayoutAccessoryButtonsForSize:(CGSize)size
351
353
verticalInset = 35 .0f ;
352
354
}
353
355
354
-
355
- UIButton *leftButton = self.leftAccessoryButton ? self.leftAccessoryButton : self.biometricButton ;
356
- if (leftButton) {
357
- [leftButton sizeToFit ];
358
- CGRect frame = leftButton.frame ;
356
+ if (self.leftButton ) {
357
+ [self .leftButton sizeToFit ];
358
+ CGRect frame = self.leftButton .frame ;
359
359
frame.origin .y = (self.view .bounds .size .height - verticalInset) - (frame.size .height * 0 .5f );
360
360
frame.origin .x = (CGRectGetMaxX (passcodeViewFrame) - buttonInset) - (frame.size .width * 0 .5f );
361
- leftButton.frame = CGRectIntegral (frame);
361
+ self. leftButton .frame = CGRectIntegral (frame);
362
362
}
363
363
364
- UIButton *rightButton = self.rightAccessoryButton ? self.rightAccessoryButton : self.cancelButton ;
365
- if (rightButton) {
366
- [rightButton sizeToFit ];
367
- CGRect frame = rightButton.frame ;
364
+ if (self.rightButton ) {
365
+ [self .rightButton sizeToFit ];
366
+ CGRect frame = self.rightButton .frame ;
368
367
frame.origin .y = verticalInset - (frame.size .height * 0 .5f );
369
368
frame.origin .x = (CGRectGetMaxX (passcodeViewFrame) - buttonInset) - (frame.size .width * 0 .5f );
370
- rightButton.frame = CGRectIntegral (frame);
369
+ self. rightButton .frame = CGRectIntegral (frame);
371
370
}
372
371
373
- [self .view bringSubviewToFront: rightButton];
374
- [self .view bringSubviewToFront: leftButton];
372
+ [self .view bringSubviewToFront: self . rightButton];
373
+ [self .view bringSubviewToFront: self . leftButton];
375
374
}
376
375
377
376
- (void )layoutAccessoryButtonsForSize : (CGSize)size
@@ -430,6 +429,9 @@ - (void)didCompleteEnteringPasscode:(NSString *)passcode
430
429
return ;
431
430
}
432
431
432
+ // Hang onto the fact the passcode was successful to play a nicer dismissal animation
433
+ self.passcodeSuccess = YES ;
434
+
433
435
// Perform handler if correctly entered
434
436
if ([self .delegate respondsToSelector: @selector (didInputCorrectPasscodeInPasscodeViewController: )]) {
435
437
[self .delegate didInputCorrectPasscodeInPasscodeViewController: self ];
@@ -471,12 +473,23 @@ - (void)keyboardWillChangeFrame:(NSNotification *)notification
471
473
presentingController : (UIViewController *)presenting
472
474
sourceController : (UIViewController *)source
473
475
{
474
- return [[TOPasscodeViewControllerAnimatedTransitioning alloc ] initWithPasscodeViewController: self dismissing: NO ];
476
+ return [[TOPasscodeViewControllerAnimatedTransitioning alloc ] initWithPasscodeViewController: self dismissing: NO success: NO ];
475
477
}
476
478
477
479
- (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController : (UIViewController *)dismissed
478
480
{
479
- return [[TOPasscodeViewControllerAnimatedTransitioning alloc ] initWithPasscodeViewController: self dismissing: YES ];
481
+ return [[TOPasscodeViewControllerAnimatedTransitioning alloc ] initWithPasscodeViewController: self dismissing: YES success: self .passcodeSuccess];
482
+ }
483
+
484
+ #pragma mark - Convenience Accessors -
485
+ - (UIView *)leftButton
486
+ {
487
+ return self.leftAccessoryButton ? self.leftAccessoryButton : self.biometricButton ;
488
+ }
489
+
490
+ - (UIView *)rightButton
491
+ {
492
+ return self.rightAccessoryButton ? self.rightAccessoryButton : self.cancelButton ;
480
493
}
481
494
482
495
#pragma mark - Public Accessors -
@@ -571,4 +584,43 @@ - (void)setAccessoryButtonTintColor:(UIColor *)accessoryButtonTintColor
571
584
[self applyThemeForStyle: self .style];
572
585
}
573
586
587
+ - (void )setContentHidden : (BOOL )contentHidden
588
+ {
589
+ [self setContentHidden: contentHidden animated: NO ];
590
+ }
591
+
592
+ - (void )setContentHidden : (BOOL )hidden animated : (BOOL )animated
593
+ {
594
+ if (hidden == _contentHidden) { return ; }
595
+ _contentHidden = hidden;
596
+
597
+ void (^setViewsHiddenBlock)(BOOL ) = ^(BOOL hidden) {
598
+ self.passcodeView .hidden = hidden;
599
+ self.leftButton .hidden = hidden;
600
+ self.rightButton .hidden = hidden;
601
+ };
602
+
603
+ void (^completionBlock)(BOOL ) = ^(BOOL complete) {
604
+ setViewsHiddenBlock (hidden);
605
+ };
606
+
607
+ if (!animated) {
608
+ completionBlock (YES );
609
+ return ;
610
+ }
611
+
612
+ // Make sure the views are visible before the animation
613
+ setViewsHiddenBlock (NO );
614
+
615
+ void (^animationBlock)() = ^{
616
+ CGFloat alpha = hidden ? 0 .0f : 1 .0f ;
617
+ self.passcodeView .contentAlpha = alpha;
618
+ self.leftButton .alpha = alpha;
619
+ self.rightButton .alpha = alpha;
620
+ };
621
+
622
+ // Animate
623
+ [UIView animateWithDuration: 0 .4f animations: animationBlock completion: completionBlock];
624
+ }
625
+
574
626
@end
0 commit comments