17
17
#import " UIView+LNPopupSupportPrivate.h"
18
18
#import " LNPopupCustomBarViewController+Private.h"
19
19
#import " _LNPopupTransitionView.h"
20
- #import " _LNPopupBarShadowedImageView.h"
20
+ #import " _LNPopupTransitionPreferredOpenAnimator.h"
21
+ #import " _LNPopupTransitionGenericOpenAnimator.h"
22
+ #import " _LNPopupTransitionGenericCloseAnimator.h"
23
+ #import " _LNPopupTransitionPreferredCloseAnimator.h"
24
+
21
25
#import < objc/runtime.h>
22
26
#import < os/log.h>
23
27
@@ -371,60 +375,24 @@ - (UIView*)_supportedUserTransitionViewFromState:(LNPopupPresentationState)fromS
371
375
return userView;
372
376
}
373
377
374
- static const void * _LNPopupOpenCloseTransitionViewKey = &_LNPopupOpenCloseTransitionViewKey;
375
-
376
378
- (void )animateOpenTransitionIfNeededWithAnimator:(UIViewPropertyAnimator*)animator userTransitionView:(UIView*)userView otherAnimations:(void (^)(void ))otherAnimations
377
379
{
378
380
if (userView == nil )
379
381
{
380
382
return ;
381
383
}
382
384
383
- __block CGRect sourceFrame;
384
- __block _LNPopupTransitionView* transitionView;
385
- __block NSShadow * targetShadow;
386
- [UIView performWithoutAnimation: ^{
387
- [self .popupContentView layoutIfNeeded ];
388
- self.popupBar .imageView .alpha = 0.0 ;
389
-
390
- sourceFrame = [self .popupBar.imageView.window convertRect: self .popupBar.imageView.bounds fromView: self .popupBar.imageView];
391
-
392
- transitionView = [[_LNPopupTransitionView alloc ] initWithFrame: sourceFrame sourceView: userView];
393
- transitionView.shadow = [((_LNPopupBarShadowedImageView*)self .popupBar.imageView).shadow copy ];
394
-
395
- targetShadow = [transitionView.shadow copy ];
396
- targetShadow.shadowColor = [targetShadow.shadowColor colorWithAlphaComponent: 0.0 ];
397
-
398
- objc_setAssociatedObject (userView, _LNPopupOpenCloseTransitionViewKey, transitionView, OBJC_ASSOCIATION_RETAIN_NONATOMIC );
399
- }];
400
-
401
- [animator addAnimations: otherAnimations];
385
+ _LNPopupTransitionOpenAnimator* handler;
386
+ if ([userView isKindOfClass: LNPopupShadowedImageView.class ])
387
+ {
388
+ handler = [[_LNPopupTransitionPreferredOpenAnimator alloc ] initWithUserView: (LNPopupShadowedImageView*)userView popupBar: self .popupBar popupContentView: self .popupContentView];
389
+ }
390
+ else
391
+ {
392
+ handler = [[_LNPopupTransitionGenericOpenAnimator alloc ] initWithUserView: userView popupBar: self .popupBar popupContentView: self .popupContentView];
393
+ }
402
394
403
- [animator addAnimations: ^{
404
- __block CGRect targetFrame;
405
- [UIView performWithoutAnimation: ^{
406
- targetFrame = [self .popupContentView.window convertRect: userView.bounds fromView: userView];
407
- CGFloat ratioX = sourceFrame.size .width / targetFrame.size .width ;
408
- CGFloat ratioY = sourceFrame.size .height / targetFrame.size .height ;
409
- transitionView.sourceViewTransform = CGAffineTransformMakeScale (ratioX, ratioY);
410
-
411
- [self .popupContentView.window addSubview: transitionView];
412
- }];
413
-
414
- transitionView.frame = targetFrame;
415
- transitionView.sourceViewTransform = CGAffineTransformIdentity;
416
- transitionView.shadow = targetShadow;
417
- }];
418
- }
419
-
420
- - (void )completeOpenTransitionIfNeededWithUserTransitionView:(UIView*)userView
421
- {
422
- [UIView performWithoutAnimation: ^{
423
- UIView* transitionView = objc_getAssociatedObject (userView, _LNPopupOpenCloseTransitionViewKey);
424
- [transitionView removeFromSuperview ];
425
- objc_setAssociatedObject (userView, _LNPopupOpenCloseTransitionViewKey, nil , OBJC_ASSOCIATION_RETAIN_NONATOMIC );
426
- self.popupBar .imageView .alpha = 1.0 ;
427
- }];
395
+ [handler animateWithAnimator: animator otherAnimations: otherAnimations];
428
396
}
429
397
430
398
- (void )animateCloseTransitionIfNeededWithAnimator:(UIViewPropertyAnimator*)animator userTransitionView:(UIView*)userView otherAnimations:(void (^)(void ))otherAnimations
@@ -434,66 +402,18 @@ - (void)animateCloseTransitionIfNeededWithAnimator:(UIViewPropertyAnimator*)anim
434
402
return ;
435
403
}
436
404
437
- __block CGRect sourceFrame;
438
- __block _LNPopupTransitionView* transitionView;
439
- __block NSShadow * targetShadow;
440
- [UIView performWithoutAnimation: ^{
441
- [self .popupContentView layoutIfNeeded ];
442
- self.popupBar .imageView .alpha = 0.0 ;
443
-
444
- sourceFrame = [self .popupContentView.window convertRect: userView.bounds fromView: userView];
445
-
446
- transitionView = [[_LNPopupTransitionView alloc ] initWithFrame: sourceFrame sourceView: userView];
447
-
448
- _LNPopupBarShadowedImageView* imageView = (id )self.popupBar .imageView ;
449
-
450
- targetShadow = [imageView.shadow copy ];
451
-
452
- NSShadow * hiddenShadow = [targetShadow copy ];
453
- hiddenShadow.shadowColor = [targetShadow.shadowColor colorWithAlphaComponent: 0.0 ];
454
- transitionView.shadow = hiddenShadow;
455
-
456
- objc_setAssociatedObject (userView, _LNPopupOpenCloseTransitionViewKey, transitionView, OBJC_ASSOCIATION_RETAIN_NONATOMIC );
457
-
458
- [self .popupContentView.window addSubview: transitionView];
459
- }];
405
+ _LNPopupTransitionCloseAnimator* handler;
460
406
461
- [animator addAnimations: ^{
462
- otherAnimations ();
463
-
464
- CGRect targetFrame = [self .popupBar.imageView.window convertRect: self .popupBar.imageView.bounds fromView: self .popupBar.imageView];
465
- [transitionView setTargetFrameUpdatingTransform: targetFrame];
466
-
467
- transitionView.shadow = targetShadow;
468
-
469
- if (self.containerController ._ln_shouldPopupContentViewFadeForTransition )
470
- {
471
- self.popupContentView .alpha = 0.0 ;
472
- }
473
- else
474
- {
475
- self.currentContentController .view .alpha = 0.0 ;
476
- }
477
- }];
407
+ if ([userView isKindOfClass: LNPopupShadowedImageView.class ])
408
+ {
409
+ handler = [[_LNPopupTransitionPreferredCloseAnimator alloc ] initWithUserView: userView popupBar: self .popupBar popupContentView: self .popupContentView currentContentController: self .currentContentController containerController: self .containerController];
410
+ }
411
+ else
412
+ {
413
+ handler = [[_LNPopupTransitionGenericCloseAnimator alloc ] initWithUserView: userView popupBar: self .popupBar popupContentView: self .popupContentView currentContentController: self .currentContentController containerController: self .containerController];
414
+ }
478
415
479
- dispatch_after (dispatch_time (DISPATCH_TIME_NOW, (int64_t )((animator.duration * 0.38 ) * NSEC_PER_SEC)), dispatch_get_main_queue (), ^{
480
- [animator addAnimations: ^{
481
- _LNPopupBarShadowedImageView* imageView = (id )self.popupBar .imageView ;
482
- transitionView.cornerRadius = imageView.cornerRadius ;
483
- }];
484
- });
485
- }
486
-
487
- - (void )completeCloseTransitionIfNeededWithUserTransitionView:(UIView*)userView
488
- {
489
- [UIView performWithoutAnimation: ^{
490
- UIView* transitionView = objc_getAssociatedObject (userView, _LNPopupOpenCloseTransitionViewKey);
491
- [transitionView removeFromSuperview ];
492
- objc_setAssociatedObject (userView, _LNPopupOpenCloseTransitionViewKey, nil , OBJC_ASSOCIATION_RETAIN_NONATOMIC );
493
- self.popupBar .imageView .alpha = 1.0 ;
494
- self.popupContentView .alpha = 1.0 ;
495
- self.currentContentController .view .alpha = 1.0 ;
496
- }];
416
+ [handler animateWithAnimator: animator otherAnimations: otherAnimations];
497
417
}
498
418
499
419
- (void )_transitionToState:(LNPopupPresentationState)state notifyDelegate:(BOOL )notifyDelegate animated:(BOOL )animated useSpringAnimation:(BOOL )spring allowPopupBarAlphaModification:(BOOL )allowBarAlpha allowFeedbackGeneration:(BOOL )allowFeedbackGeneration forceFeedbackGenerationAtStart:(BOOL )forceFeedbackAtStart completion:(void (^)(void ))completion
@@ -726,26 +646,20 @@ - (void)_transitionToState:(LNPopupPresentationState)state notifyDelegate:(BOOL)
726
646
if (userView != nil )
727
647
{
728
648
animationDuration *= 1.25 ;
649
+ // animationDuration = 4;
729
650
}
730
651
731
652
_runningPopupAnimation = [[UIViewPropertyAnimator alloc ] initWithDuration: animationDuration dampingRatio: spring && userView == nil ? 0.85 : 1.0 animations: nil ];
653
+ // _runningPopupAnimation = [[UIViewPropertyAnimator alloc] initWithDuration:animationDuration curve:UIViewAnimationCurveLinear animations:nil];
732
654
_runningPopupAnimation.userInteractionEnabled = NO ;
733
655
734
656
if (stateAtStart == LNPopupPresentationStateBarPresented && userView != nil )
735
657
{
736
658
[self animateOpenTransitionIfNeededWithAnimator: _runningPopupAnimation userTransitionView: userView otherAnimations: animationBlock];
737
-
738
- [_runningPopupAnimation addCompletion: ^(UIViewAnimatingPosition finalPosition) {
739
- [self completeOpenTransitionIfNeededWithUserTransitionView: userView];
740
- }];
741
659
}
742
660
else if (state == LNPopupPresentationStateBarPresented && userView != nil )
743
661
{
744
662
[self animateCloseTransitionIfNeededWithAnimator: _runningPopupAnimation userTransitionView: userView otherAnimations: animationBlock];
745
-
746
- [_runningPopupAnimation addCompletion: ^(UIViewAnimatingPosition finalPosition) {
747
- [self completeCloseTransitionIfNeededWithUserTransitionView: userView];
748
- }];
749
663
}
750
664
else
751
665
{
0 commit comments