void CompleteTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            if (transitionContext.IsInteractive)
            {
                if (transitionContext.TransitionWasCancelled)
                {
                    transitionContext.CancelInteractiveTransition();
                }
                else
                {
                    transitionContext.FinishInteractiveTransition();
                }
            }

            transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
        }
        void EndInteraction(bool success)
        {
            if (context == null)
            {
                HasActiveInteraction = false;
                return;
            }

            if (success && (transitionLayout.TransitionProgress > 0.5f))
            {
                collectionView.FinishInteractiveTransition();
                context.FinishInteractiveTransition();
            }
            else
            {
                collectionView.CancelInteractiveTransition();
                context.CancelInteractiveTransition();
            }
        }
Exemplo n.º 3
0
 // called by our pinch gesture recognizer when the gesture has finished or cancelled, which
 // in turn is responsible for finishing or cancelling the transition.
 void EndInteraction(bool success)
 {
     if (context == null)
     {
         HasActiveInteraction = false;
     }
     // allow for the transition to finish when it's progress has started as a threshold of 10%,
     // if you want to require the pinch gesture with a wider threshold, change it it a value closer to 1.0
     //
     else if ((transitionLayout.TransitionProgress > 0.1f) && success)
     {
         collectionView.FinishInteractiveTransition();
         context.FinishInteractiveTransition();
     }
     else
     {
         collectionView.CancelInteractiveTransition();
         context.CancelInteractiveTransition();
     }
 }
        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;
            }
        }
        //Called when a Push/Pop/Swipe back happens
        public override void StartInteractiveTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            context = transitionContext;
            lastPercent = 1f;
            animationStarted = true;
            var inView = transitionContext.ContainerView;
            var fromVC = transitionContext.GetViewControllerForKey (UITransitionContext.FromViewControllerKey);
            var fromView = fromVC.View;
            var toVC = transitionContext.GetViewControllerForKey (UITransitionContext.ToViewControllerKey);
            var toView = toVC.View;

            var frame = toView.Frame;

            if (reverse) {
                inView.InsertSubviewBelow (toView, fromVC.View);
                toView.Frame = new CGRect (-inView.Frame.Width, 0, frame.Width, frame.Height);
            } else {
                inView.AddSubview (toView);
                toView.Frame = new CGRect (inView.Frame.Width, 0, frame.Width, frame.Height);
            }

            UIView.Animate (Duration,0,UIViewAnimationOptions.AllowUserInteraction, () => {
                if (reverse) {
                    fromView.Frame = new CGRect (inView.Frame.Width, 0, frame.Width, frame.Height);
                    toView.Frame = new CGRect (0, 0, frame.Width, frame.Height);
                } else {
                    fromView.Frame = new CGRect (-inView.Frame.Width, 0, frame.Width, frame.Height);
                    toView.Frame = new CGRect (0, 0, frame.Width, frame.Height);
                }
            }, () => {
                if (animationStarted){
                    context.FinishInteractiveTransition();
                    context.CompleteTransition (true);
                    context=null;
                }
                animationStarted=false;
            });
        }