From b9f564ff4b0213c90fd89fb65aff5ee18f3f6c3a Mon Sep 17 00:00:00 2001 From: John D in the UK Date: Tue, 10 Mar 2020 15:12:14 +0000 Subject: [PATCH] Updated ViewController to resist Pan interaction below a percentage threshold of animation completed. --- CardViewAnimation/ViewController.swift | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/CardViewAnimation/ViewController.swift b/CardViewAnimation/ViewController.swift index 1615c44..b9cfc66 100644 --- a/CardViewAnimation/ViewController.swift +++ b/CardViewAnimation/ViewController.swift @@ -21,7 +21,8 @@ class ViewController: UIViewController { let cardHeight:CGFloat = 600 let cardHandleAreaHeight:CGFloat = 65 - + var fractionComplete:CGFloat = 0 + var cardVisible = false var nextState:CardState { return cardVisible ? .collapsed : .expanded @@ -74,10 +75,17 @@ class ViewController: UIViewController { startInteractiveTransition(state: nextState, duration: 0.9) case .changed: let translation = recognizer.translation(in: self.cardViewController.handleArea) - var fractionComplete = translation.y / cardHeight + fractionComplete = translation.y / cardHeight fractionComplete = cardVisible ? fractionComplete : -fractionComplete updateInteractiveTransition(fractionCompleted: fractionComplete) case .ended: + if fractionComplete < 0.25 { + for animator in runningAnimations { + animator.isReversed = true + } + self.cardVisible = !self.cardVisible + self.visualEffectView.isUserInteractionEnabled = !self.visualEffectView.isUserInteractionEnabled + } continueInteractiveTransition() default: break