Example #1
0
        public void Rotate()
        {
            CASpringAnimation rotationAnimation = new CASpringAnimation();

            rotationAnimation.KeyPath             = "transform.rotation.z";
            rotationAnimation.RepeatCount         = 1;
            rotationAnimation.InitialVelocity     = 5;
            rotationAnimation.Mass                = 1.5f;
            rotationAnimation.RemovedOnCompletion = false;
            rotationAnimation.FillMode            = CAFillMode.Forwards;

            if (upsideDown)
            {
                rotationAnimation.From = new NSNumber(Math.PI);
                rotationAnimation.To   = new NSNumber(Math.PI * 2);
            }
            else
            {
                rotationAnimation.From = new NSNumber(0);
                rotationAnimation.To   = new NSNumber(Math.PI);
            }
            rotationAnimation.Duration = rotationAnimation.SettlingDuration;

            Layer.AddAnimation(rotationAnimation, nameof(rotationAnimation));

            upsideDown = !upsideDown;
        }
            public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
            {
                var toViewController = transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);
                var containerView    = transitionContext.ContainerView;

                var animationDuration = TransitionDuration(transitionContext);

                var animation = (CASpringAnimation)CASpringAnimation.FromKeyPath("position.y");

                animation.Damping         = 10;
                animation.InitialVelocity = 20;
                animation.Mass            = 1;
                animation.Stiffness       = 100;
                animation.From            = FromObject(containerView.Bounds.Height);
                animation.To                = FromObject(UIScreen.MainScreen.Bounds.Height / 2);
                animation.Duration          = TransitionDuration(transitionContext);
                animation.AnimationStopped += delegate
                {
                    transitionContext.CompleteTransition(true);
                };

                toViewController.View.Layer.AddAnimation(animation, null);

                containerView.AddSubview(toViewController.View);
            }