void FinishPan(UIPanGestureRecognizer panGestureRecognizer, nfloat verticalDelta, UIView viewToPan, CGPoint anchorPoint) { var fromView = _transitionContext?.GetViewFor(UITransitionContext.FromViewKey); var velocityY = panGestureRecognizer.VelocityInView(panGestureRecognizer.View).Y; var animationDuration = Math.Abs(velocityY) * PhotoDismissalInteractionControllerReturnToCenterVelocityAnimationRatio + 0.2; var animationCurve = UIViewAnimationOptions.CurveEaseOut; var finalPageViewCenterPount = anchorPoint; var finalBackgroundAlpha = 1.0f; var dismissDistance = (fromView == null) ? 0.0f : PhotoDismissalInteractionControllerPanDismissDistanceRatio * fromView.Bounds.Height; var isDismissing = Math.Abs(verticalDelta) > dismissDistance; var didAnimateUsingAnimator = false; if (isDismissing) { if (ShouldAnimateUsingAnimator) { Animator.AnimateTransition(_transitionContext); didAnimateUsingAnimator = true; } else { var isPositiveDelta = verticalDelta >= 0; var modifier = isPositiveDelta ? 1 : -1; if (fromView == null) { finalPageViewCenterPount = new CGPoint(0.0f, 0.0f); } else { var finalCenterY = fromView.Bounds.GetMidY() + modifier * fromView.Bounds.Height; finalPageViewCenterPount = new CGPoint(fromView.Center.X, finalCenterY); } animationDuration = Math.Abs(finalPageViewCenterPount.Y - viewToPan.Center.Y) / Math.Abs(velocityY); animationDuration = Math.Min(animationDuration, PhotoDismissalInteractionControllerPanDismissMaximumDuration); animationCurve = UIViewAnimationOptions.CurveEaseOut; finalBackgroundAlpha = 0.0f; } } if (!didAnimateUsingAnimator) { UIView.Animate(animationDuration, 0, animationCurve, () => { viewToPan.Center = finalPageViewCenterPount; fromView.BackgroundColor = fromView.BackgroundColor.ColorWithAlpha(finalBackgroundAlpha); }, () => { if (isDismissing) { _transitionContext.FinishInteractiveTransition(); } else { _transitionContext.CancelInteractiveTransition(); } if (ViewToHideWhenBeginningTransition != null) { ViewToHideWhenBeginningTransition.Alpha = 1.0f; } _transitionContext.CompleteTransition(isDismissing && !_transitionContext.TransitionWasCancelled); _transitionContext = null; } ); } else { _transitionContext = null; } }