123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- #import "TOPasscodeViewControllerAnimatedTransitioning.h"
- #import "TOPasscodeViewController.h"
- #import "TOPasscodeView.h"
- @interface TOPasscodeViewControllerAnimatedTransitioning ()
- @property (nonatomic, weak) TOPasscodeViewController *passcodeViewController;
- @end
- @implementation TOPasscodeViewControllerAnimatedTransitioning
- - (instancetype)initWithPasscodeViewController:(TOPasscodeViewController *)passcodeViewController dismissing:(BOOL)dismissing success:(BOOL)success
- {
- if (self = [super init]) {
- _passcodeViewController = passcodeViewController;
- _dismissing = dismissing;
- _success = success;
- }
- return self;
- }
- - (NSTimeInterval)transitionDuration:(nullable id <UIViewControllerContextTransitioning>)transitionContext
- {
- return 0.35f;
- }
- - (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext
- {
- BOOL isPhone = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
- UIView *containerView = transitionContext.containerView;
- UIVisualEffectView *backgroundEffectView = self.passcodeViewController.backgroundEffectView;
- UIView *backgroundView = self.passcodeViewController.backgroundView;
- UIVisualEffect *backgroundEffect = backgroundEffectView.effect;
- TOPasscodeView *passcodeView = self.passcodeViewController.passcodeView;
-
- if (!self.dismissing) {
- backgroundEffectView.effect = nil;
- backgroundView.alpha = 0.0f;
- self.passcodeViewController.view.frame = containerView.bounds;
- [containerView addSubview:self.passcodeViewController.view];
- }
- else {
- UIViewController *baseController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];
- if (baseController.view.superview == nil) {
- [containerView insertSubview:baseController.view atIndex:0];
- }
- }
- CGFloat alpha = self.dismissing ? 1.0f : 0.0f;
- passcodeView.contentAlpha = alpha;
-
- if (isPhone) {
- self.passcodeViewController.leftAccessoryButton.alpha = alpha;
- self.passcodeViewController.rightAccessoryButton.alpha = alpha;
- self.passcodeViewController.cancelButton.alpha = alpha;
- self.passcodeViewController.biometricButton.alpha = alpha;
- }
- id animationBlock = ^{
- backgroundEffectView.effect = self.dismissing ? nil : backgroundEffect;
- backgroundView.alpha = self.dismissing ? 0.0f : 1.0f;
- CGFloat toAlpha = self.dismissing ? 0.0f : 1.0f;
- passcodeView.contentAlpha = toAlpha;
- if (isPhone) {
- self.passcodeViewController.leftAccessoryButton.alpha = toAlpha;
- self.passcodeViewController.rightAccessoryButton.alpha = toAlpha;
- self.passcodeViewController.cancelButton.alpha = toAlpha;
- self.passcodeViewController.biometricButton.alpha = toAlpha;
- }
- };
- id completedBlock = ^(BOOL completed) {
- backgroundEffectView.effect = backgroundEffect;
- [transitionContext completeTransition:completed];
- };
-
-
- if (self.success && self.dismissing) {
- CABasicAnimation *animation = [CABasicAnimation animationWithKeyPath:@"transform"];
- animation.duration = [self transitionDuration:transitionContext];
- animation.toValue = [NSValue valueWithCATransform3D:CATransform3DMakeScale(0.9f, 0.9f, 1)];
- animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
- [passcodeView.layer addAnimation:animation forKey:@"transform"];
- }
- [UIView animateWithDuration:[self transitionDuration:transitionContext]
- delay:0.0f
- options:UIViewAnimationOptionAllowUserInteraction
- animations:animationBlock
- completion:completedBlock];
- }
- @end
|