Esempio n. 1
0
        void AnimateToCompact()
        {
            UIView.AddKeyframeWithRelativeStartTime(0.0, 1.0, () => {
                NSLayoutConstraint.DeactivateConstraints(new [] { marsLeadingToTrailing, jupiterLeadingToTrailing, saturnLeadingToTrailing });
                NSLayoutConstraint.ActivateConstraints(new [] { marsCenter, jupiterCenter, saturnCenter });
                View.LayoutIfNeeded();
            });

            UIView.AddKeyframeWithRelativeStartTime(0.1, 0.9, () => {
                NSLayoutConstraint.DeactivateConstraints(new [] { earthLeadingToTrailing, uranusLeadingToTrailing });
                NSLayoutConstraint.ActivateConstraints(new [] { earthCenter, uranusCenter });
                View.LayoutIfNeeded();
            });

            UIView.AddKeyframeWithRelativeStartTime(0.3, 0.7, () => {
                NSLayoutConstraint.DeactivateConstraints(new [] { venusLeadingToTrailing, neptuneLeadingToTrailing });
                NSLayoutConstraint.ActivateConstraints(new [] { venusCenter, neptuneCenter });
                View.LayoutIfNeeded();
            });

            UIView.AddKeyframeWithRelativeStartTime(0.5, 0.5, () => {
                NSLayoutConstraint.DeactivateConstraints(new [] { mercuryLeadingToTrailing });
                NSLayoutConstraint.ActivateConstraints(new [] { mercuryCenter });
                View.LayoutIfNeeded();
            });
        }
 /// Default action when dimissing showcase
 /// Notifies delegate, removes views, and handles out-going animation
 public static void CompleteShowcase(this MaterialShowcase materialShowcase, bool animated = true)
 {
     if (animated)
     {
         materialShowcase.targetRippleView.RemoveFromSuperview();
         UIView.AnimateKeyframes(materialShowcase.aniGoOutDuration, 0, UIViewKeyframeAnimationOptions.CalculationModeLinear, () =>
         {
             UIView.AddKeyframeWithRelativeStartTime(0, .6f, () =>
             {
                 materialShowcase.targetHolderView.Transform = CGAffineTransform.MakeScale(.4f, .4f);
                 materialShowcase.backgroundView.Transform   = CGAffineTransform.MakeScale(1.3f, 1.3f);
                 materialShowcase.backgroundView.Alpha       = 0;
             });
             UIView.AddKeyframeWithRelativeStartTime(.6f, .4f, () =>
             {
                 materialShowcase.Alpha = 0;
             });
         }, (success) =>
         {
             // Recycle subviews
             materialShowcase.RecycleSubviews();
             // Remove it from current screen
             materialShowcase.RemoveFromSuperview();
         });
     }
     else
     {
         // Recycle subviews
         materialShowcase.RecycleSubviews();
         // Remove it from current screen
         materialShowcase.RemoveFromSuperview();
     }
 }
        void AnimateViewWithKeyframes(UIView rectangle, int min, int max)
        {
            var x = rectangle.Frame.X;

            var h1 = Rnd.Next(min, max);
            var h2 = Rnd.Next(min, max);
            var h3 = Rnd.Next(min, max);
            var h4 = Rnd.Next(min, max);

            UIView.AnimateKeyframes(0.75f, 0, UIViewKeyframeAnimationOptions.Autoreverse | UIViewKeyframeAnimationOptions.Repeat, () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.25, () =>
                {
                    rectangle.Frame = new RectangleF(x, 45, 5, h1);
                });

                UIView.AddKeyframeWithRelativeStartTime(0.25, 0.25, () =>
                {
                    rectangle.Frame = new RectangleF(x, 45, 5, h2);
                });

                UIView.AddKeyframeWithRelativeStartTime(0.5, 0.25, () =>
                {
                    rectangle.Frame = new RectangleF(x, 45, 5, h3);
                });

                UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25, () =>
                {
                    rectangle.Frame = new RectangleF(x, 45, 5, h4);
                });
            }, _ => { });
        }
Esempio n. 4
0
        public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            var toViewController   = GetViewController(transitionContext, UITransitionContext.ToViewControllerKey);
            var fromViewController = GetViewController(transitionContext, UITransitionContext.FromViewControllerKey);

            UIView fromView = fromViewController.View;
            UIView toView   = toViewController.View;


            UIView containerView = transitionContext.ContainerView;

            containerView.AddSubview(toView);

            // Add a perspective transform
            var transform = CATransform3D.Identity;

            transform.m34 = -0.002f;
            containerView.Layer.SublayerTransform = transform;

            // Give both VCs the same start frame
            CGRect initialFrame = transitionContext.GetInitialFrameForViewController(fromViewController);

            fromView.Frame = initialFrame;
            toView.Frame   = initialFrame;

            float factor = Reverse ? 1f : -1f;

            // flip the to VC halfway round - hiding it
            toView.Layer.Transform = GetRotation(factor * -(float)Math.PI / 2);
            double duration = TransitionDuration(transitionContext);

            Action animations = () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.5, () =>
                {
                    fromView.Layer.Transform = GetRotation(factor * (float)Math.PI / 2);
                });

                UIView.AddKeyframeWithRelativeStartTime(0.5, 0.5, () =>
                {
                    toView.Layer.Transform = GetRotation(0f);
                });
            };

            UIView.AnimateKeyframes(duration, 0.0, UIViewKeyframeAnimationOptions.CalculationModeLinear, animations, (finished) =>
            {
                transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
            });
        }
Esempio n. 5
0
        private void ExecuteReverseAnimation(IUIViewControllerContextTransitioning transitionContext,
                                             UIViewController fromViewController, UIViewController toViewController,
                                             UIView fromView, UIView toView)
        {
            UIView containerView = transitionContext.ContainerView;

            // positions the to- view behind the from- view
            toView.Frame = containerView.Frame;
            var scale = CATransform3D.Identity;

            toView.Layer.Transform = scale.Scale(0.6f, 0.6f, 1f);
            toView.Alpha           = 0.6f;

            containerView.InsertSubviewAbove(toView, fromView);

            CGRect frameOffScreen = containerView.Frame;

            frameOffScreen.Y = containerView.Frame.Height;

            CATransform3D transform = GetFirstTransform();

            Action animations = () => {
                // push the from- view off the bottom of the screen
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.5, () => {
                    fromView.Frame = frameOffScreen;
                });

                // animate the to- view into place
                UIView.AddKeyframeWithRelativeStartTime(0.35, 0.35, () => {
                    toView.Layer.Transform = transform;
                    toView.Alpha           = 1f;
                });

                UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25, () => {
                    toView.Layer.Transform = CATransform3D.Identity;
                });
            };

            UIView.AnimateKeyframes(Duration, 0.0, UIViewKeyframeAnimationOptions.CalculationModeCubic, animations, (finished) => {
                if (transitionContext.TransitionWasCancelled)
                {
                    toView.Layer.Transform = CATransform3D.Identity;
                    toView.Alpha           = 1f;
                }

                transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
            });
        }
Esempio n. 6
0
        private void ExecuteForwardAnimation(IUIViewControllerContextTransitioning transitionContext,
                                             UIViewController fromViewController, UIViewController toViewController,
                                             UIView fromView, UIView toView)
        {
            UIView containerView = transitionContext.ContainerView;

            // positions the to- view off the bottom of the sceen
            CGRect offScreenFrame = containerView.Frame;

            offScreenFrame.Y = containerView.Frame.Height;
            toView.Frame     = offScreenFrame;

            containerView.InsertSubviewAbove(toView, fromView);

            CATransform3D firstTransform  = GetFirstTransform();
            CATransform3D secondTrsnaform = GetSecondTransform(fromView);

            Action animations = () => {
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.4, () => {
                    fromView.Layer.Transform = firstTransform;
                    fromView.Alpha           = 0.6f;
                });

                UIView.AddKeyframeWithRelativeStartTime(0.2, 0.4, () => {
                    fromView.Layer.Transform = secondTrsnaform;
                });

                UIView.AddKeyframeWithRelativeStartTime(0.6, 0.2, () => {
                    toView.Frame = new CGRect(toView.Frame.X, containerView.Frame.Y - 30f,
                                              toView.Frame.Width, toView.Frame.Height);
                });

                UIView.AddKeyframeWithRelativeStartTime(0.8, 0.2, () => {
                    toView.Frame = containerView.Frame;
                });
            };

            UIView.AnimateKeyframes(Duration, 0.0, UIViewKeyframeAnimationOptions.CalculationModeCubic, animations, (finished) => {
                transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
            });
        }
Esempio n. 7
0
        void StartAnimations()
        {
            //			var options = UIViewKeyframeAnimationOptions.Repeat | UIViewKeyframeAnimationOptions.CalculationModeCubicPaced UIViewKeyframeAnimationOptions = [.curveEaseInOut, .repeat]
            UIViewKeyframeAnimationOptions options = UIViewKeyframeAnimationOptions.Repeat | (UIViewKeyframeAnimationOptions)UIViewAnimationOptions.CurveEaseInOut;

            UIView.AnimateKeyframes(AniRippleStartScale + AniRippleEndScale, 0, options, () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0, AniRippleStartDuration, () =>
                {
                    _targetRippleView.Alpha     = AniRippleAlpha;
                    _targetHolderView.Transform = CGAffineTransform.MakeScale(AniRippleEndScale, AniRippleEndScale);
                    _targetRippleView.Transform = CGAffineTransform.MakeScale(AniRippleEndScale, AniRippleEndScale);
                });
                UIView.AddKeyframeWithRelativeStartTime(AniRippleStartDuration, AniRippleEndDuration, () =>
                {
                    _targetHolderView.Transform = CGAffineTransform.MakeIdentity();
                    _targetRippleView.Alpha     = 0;
                    _targetRippleView.Transform = CGAffineTransform.MakeScale(AniRippleStartScale, AniRippleStartScale);
                });
            }, success => { });
        }
Esempio n. 8
0
        void AnimateViewWithKeyframes()
        {
            var initialTransform = imageView.Transform;
            var initialCeneter   = imageView.Center;

            // can now use keyframes directly on UIView without needing to drop directly into Core Animation

            UIView.AnimateKeyframes(2.0, 0, UIViewKeyframeAnimationOptions.Autoreverse, () => {
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.5, () => {
                    imageView.Center = new CGPoint(200, 200);
                });

                UIView.AddKeyframeWithRelativeStartTime(0.5, 0.5, () => {
                    imageView.Transform = CGAffineTransform.MakeRotation((float)Math.PI / 2);
                });
            }, (finished) => {
                imageView.Center    = initialCeneter;
                imageView.Transform = initialTransform;

                AnimateWithSpring();
            });
        }
Esempio n. 9
0
 public void CompleteShowcase(bool animated = true, bool skipped = false)
 {
     UndoStatusBar(animated);
     ShowCaseWillDismiss?.Invoke(skipped);
     if (animated)
     {
         _targetRippleView.RemoveFromSuperview();
         UIView.AnimateKeyframes(AniGoOutDuration, 0, UIViewKeyframeAnimationOptions.CalculationModeLinear,
                                 () =>
         {
             UIView.AddKeyframeWithRelativeStartTime(0, 3 / 5f, () =>
             {
                 _targetHolderView.Transform = CGAffineTransform.MakeScale(0.4f, 0.4f);
                 _backgroundView.Transform   = CGAffineTransform.MakeScale(1.3f, 1.3f);
                 _backgroundView.Alpha       = 0;
             });
             UIView.AddKeyframeWithRelativeStartTime(3 / 5f, 2 / 5f, () => { Alpha = 0; });
         },
                                 success =>
         {
             if (success)
             {
                 RecycleSubviews();
                 // Remove it from current screen
                 RemoveFromSuperview();
                 ShowCaseDidDismiss?.Invoke(skipped);
             }
         });
     }
     else
     {
         // Recycle subviews
         RecycleSubviews();
         // Remove it from current screen
         RemoveFromSuperview();
         ShowCaseDidDismiss?.Invoke(skipped);
     }
 }
        public static void StartAnimation(this MaterialShowcase materialShowcase)
        {
            UIViewKeyframeAnimationOptions options = UIViewKeyframeAnimationOptions.Repeat | 0 << 16;

            UIView.AnimateKeyframes(1, 0, options, () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0, .5f, () =>
                {
                    materialShowcase.targetRippleView.Alpha     = MaterialShowcase.AniRippleAlpha;
                    materialShowcase.targetHolderView.Transform = CGAffineTransform.MakeScale(1.1f, 1.1f);
                    materialShowcase.targetRippleView.Transform = CGAffineTransform.MakeScale(1.1f, 1.1f);
                });
                UIView.AddKeyframeWithRelativeStartTime(.5f, .5f, () =>
                {
                    materialShowcase.targetHolderView.Transform = CGAffineTransform.MakeIdentity();
                    materialShowcase.targetRippleView.Alpha     = 0;
                    materialShowcase.targetRippleView.Transform = CGAffineTransform.MakeScale(materialShowcase.aniRippleScale, materialShowcase.aniRippleScale);
                });
            }, (completion) =>
            {
                Console.WriteLine("ok");
            });
        }
Esempio n. 11
0
            private void SetStopTimeHidden(bool hidden, bool animate)
            {
                if (stopTimeHidden == hidden)
                {
                    return;
                }
                stopTimeHidden = hidden;

                if (!animate)
                {
                    ViewLayout = hidden ? LayoutVariant.StartOnly : LayoutVariant.BothCenterAll;
                }
                else if (hidden)
                {
                    ViewLayout = LayoutVariant.BothCenterAll;
                    stopDateTimeButton.Alpha = 1;
                    arrowImageView.Alpha     = 1;
                    LayoutIfNeeded();

                    UIView.AnimateKeyframes(
                        0.4, 0,
                        UIViewKeyframeAnimationOptions.CalculationModeCubic | UIViewKeyframeAnimationOptions.BeginFromCurrentState,
                        delegate {
                        UIView.AddKeyframeWithRelativeStartTime(0, 1, delegate {
                            ViewLayout = LayoutVariant.BothCenterStart;
                            LayoutIfNeeded();
                        });
                        UIView.AddKeyframeWithRelativeStartTime(0, 0.8, delegate {
                            stopDateTimeButton.Alpha = 0;
                            arrowImageView.Alpha     = 0;
                        });
                    },
                        delegate {
                        if (ViewLayout == LayoutVariant.BothCenterStart)
                        {
                            ViewLayout = LayoutVariant.StartOnly;
                            LayoutIfNeeded();
                        }
                    });
                }
                else
                {
                    ViewLayout = LayoutVariant.BothCenterStart;
                    stopDateTimeButton.Alpha = 0;
                    arrowImageView.Alpha     = 0;
                    LayoutIfNeeded();

                    UIView.AnimateKeyframes(
                        0.4, 0,
                        UIViewKeyframeAnimationOptions.CalculationModeCubic | UIViewKeyframeAnimationOptions.BeginFromCurrentState,
                        delegate {
                        UIView.AddKeyframeWithRelativeStartTime(0, 1, delegate {
                            ViewLayout = LayoutVariant.BothCenterAll;
                            LayoutIfNeeded();
                        });
                        UIView.AddKeyframeWithRelativeStartTime(0.2, 1, delegate {
                            stopDateTimeButton.Alpha = 1;
                            arrowImageView.Alpha     = 1;
                        });
                    },
                        delegate {
                    });
                }
            }
        public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext,
                                               UIViewController fromViewController, UIViewController toViewController,
                                               UIView fromView, UIView toView)
        {
            UIView containerView = transitionContext.ContainerView;

            containerView.AddSubview(toView);
            containerView.SendSubviewToBack(toView);

            var transform = CATransform3D.Identity;

            transform.m34 = -0.002f;
            containerView.Layer.SublayerTransform = transform;

            var initialFrame = transitionContext.GetInitialFrameForViewController(fromViewController);

            fromView.Frame = initialFrame;
            toView.Frame   = initialFrame;

            List <UIView> toViewSnapshots        = CreateSnapshots(toView, true);
            UIView        flippedSectionOfToView = toViewSnapshots [Reverse ? 0 : 1];

            List <UIView> fromViewSnapshots        = CreateSnapshots(fromView, false);
            UIView        flippedSectionOfFromView = fromViewSnapshots [Reverse ? 1 : 0];

            flippedSectionOfFromView = AddShadowToView(flippedSectionOfFromView, !Reverse);
            UIView flippedSectionOfFromViewShadow = flippedSectionOfFromView.Subviews [1];

            flippedSectionOfFromViewShadow.Alpha = 0f;

            flippedSectionOfToView = AddShadowToView(flippedSectionOfToView, Reverse);
            UIView flippedSectionOfToViewShadow = flippedSectionOfToView.Subviews [1];

            flippedSectionOfToViewShadow.Alpha = 1f;

            // change the anchor point so that the view rotate around the correct edge
            UpdateAnchorPointAndOffset(new CGPoint(Reverse ? 0f : 1f, 0.5f), flippedSectionOfFromView);
            UpdateAnchorPointAndOffset(new CGPoint(Reverse ? 1f : 0f, 0.5f), flippedSectionOfToView);

            flippedSectionOfToView.Layer.Transform = Rotate(Reverse ? (float)Math.PI / 2 : -(float)Math.PI / 2);
            double duration = TransitionDuration(transitionContext);

            Action animations = () => {
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.5, () => {
                    flippedSectionOfFromView.Layer.Transform = Rotate(Reverse ? -(float)Math.PI / 2 : (float)Math.PI / 2);
                    flippedSectionOfFromViewShadow.Alpha     = 1f;
                });

                UIView.AddKeyframeWithRelativeStartTime(0.5, 0.5, () => {
                    flippedSectionOfToView.Layer.Transform = Rotate(Reverse ? 0.001f : -0.001f);
                    flippedSectionOfToViewShadow.Alpha     = 0f;
                });
            };

            UIView.AnimateKeyframes(duration, 0.0, UIViewKeyframeAnimationOptions.CalculationModeLinear, animations, (finished) => {
                if (transitionContext.TransitionWasCancelled)
                {
                    RemoveOtherViews(fromView);
                }
                else
                {
                    RemoveOtherViews(toView);
                }

                transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
            });
        }
        public override void AnimateTransition(IUIViewControllerContextTransitioning transitionContext)
        {
            var fromVC = (GarlandViewController)transitionContext.GetViewControllerForKey(UITransitionContext.FromViewControllerKey);
            var toVC   = (GarlandViewController)transitionContext.GetViewControllerForKey(UITransitionContext.ToViewControllerKey);

            var fromHeaderSnapshot = fromVC.HeaderView.SnapshotView(true);

            if (fromHeaderSnapshot == null)
            {
                transitionContext.CompleteTransition(false); return;
            }

            var fromCollection = fromVC.Collection;
            var toCollection   = toVC.Collection;

            var containerView = transitionContext.ContainerView;

            containerView.Frame = fromVC.View.Frame;
            containerView.AddSubview(toVC.View);
            toVC.View.Frame = UIScreen.MainScreen.Bounds;
            toVC.View.LayoutSubviews();

            var toHeaderSnapshot        = toVC.HeaderView.SnapshotView(true);
            var rightFakeHeaderSnapshot = toVC.RightFakeHeader.SnapshotView(true);
            var leftFakeHeaderSnapshot  = toVC.LeftFakeHeader.SnapshotView(true);

            if (toHeaderSnapshot == null || rightFakeHeaderSnapshot == null || leftFakeHeaderSnapshot == null)
            {
                transitionContext.CompleteTransition(false); return;
            }

            var headerStartFrame = fromVC.View.ConvertRectToView(fromVC.HeaderView.Frame, containerView);
            var headerFinalFrame = CreateRect(headerStartFrame, toHeaderSnapshot.Frame.Size);

            //generate & configure cells transition views
            var visibleFromSnapshots    = new List <UIView>();
            var overlappedCells         = new List <UIView>();
            var convertedFromCellCoords = new List <CGPoint>();
            var cellSize = new List <CGSize>();

            foreach (var cell in fromCollection.VisibleCells)
            {
                var cellSnap = cell.SnapshotView(true);
                if (cellSnap == null)
                {
                    continue;
                }

                var convertedCoord = fromCollection.ConvertPointToView(new CGPoint(cell.Frame.X, cell.Frame.Y), null); //NULL HERE
                cellSnap.Frame = new CGRect(convertedCoord.X, convertedCoord.Y, cell.Frame.Width, cell.Frame.Height);
                cellSize.Add(new CGSize(cell.Frame.Width, cell.Frame.Height));
                if (convertedCoord.Y < headerStartFrame.GetMinY())
                {
                    cellSnap.Alpha = 0;
                }
                else if (convertedCoord.Y < headerStartFrame.GetMaxY())
                {
                    overlappedCells.Add(cellSnap);
                }
                var config = GarlandConfig.Instance;
                cellSnap.Layer.CornerRadius  = config.CardRadius;
                cellSnap.Layer.ShadowOffset  = config.CardShadowOffset;
                cellSnap.Layer.ShadowColor   = config.CardShadowColor.CGColor;
                cellSnap.Layer.ShadowOpacity = config.CardShadowOpacity;
                cellSnap.Layer.ShadowRadius  = config.CardShadowRadius;
                visibleFromSnapshots.Add(cellSnap);
                containerView.AddSubview(cellSnap);
            }

            var visibleToSnapshots = new List <UIView>();

            foreach (var cell in toCollection.VisibleCells)
            {
                var cellSnap = cell.SnapshotView(true);
                if (cellSnap == null)
                {
                    continue;
                }

                var convertedCoord = toCollection.ConvertPointToView(new CGPoint(cell.Frame.X, cell.Frame.Y), null); //.. AND HERE
                convertedFromCellCoords.Add(convertedCoord);
                cellSnap.Frame = new CGRect(new CGPoint(cellSnap.Frame.X, cellSnap.Frame.Y), new CGSize(cellSnap.Frame.Width / 3, cellSnap.Frame.Height / 2));
                var finalX = this.finalFromXFrame;
                if (finalX == UIScreen.MainScreen.Bounds.Width)
                {
                    finalX += cellSnap.Frame.Width;
                }
                var newPoint = new CGPoint(UIScreen.MainScreen.Bounds.Width - finalX, convertedCoord.Y + cellSnap.Frame.Height / 2);
                cellSnap.Frame = new CGRect(newPoint, cellSnap.Frame.Size);
                cellSnap.Alpha = 0.2f;

                var config = GarlandConfig.Instance;
                cellSnap.Layer.CornerRadius  = config.CardRadius;
                cellSnap.Layer.ShadowOffset  = config.CardShadowOffset;
                cellSnap.Layer.ShadowColor   = config.CardShadowColor.CGColor;
                cellSnap.Layer.ShadowOpacity = config.CardShadowOpacity;
                cellSnap.Layer.ShadowRadius  = config.CardShadowRadius;
                visibleToSnapshots.Add(cellSnap);
                containerView.AddSubview(cellSnap);
            }

            //configure headers
            fromHeaderSnapshot.Frame = headerStartFrame;
            var configuration = GarlandConfig.Instance;

            fromHeaderSnapshot.Layer.MasksToBounds = false;
            fromHeaderSnapshot.Layer.CornerRadius  = configuration.CardRadius;
            fromHeaderSnapshot.Layer.ShadowOffset  = configuration.CardShadowOffset;
            fromHeaderSnapshot.Layer.ShadowColor   = configuration.CardShadowColor.CGColor;
            fromHeaderSnapshot.Layer.ShadowOpacity = configuration.CardShadowOpacity;
            fromHeaderSnapshot.Layer.ShadowRadius  = configuration.CardShadowRadius;

            var toFakeHeader           = finalFromXFrame == 0 ? toVC.RightFakeHeader : toVC.LeftFakeHeader;
            var fromFakeHeader         = finalFromXFrame == 0 ? toVC.LeftFakeHeader : toVC.RightFakeHeader;
            var toFakeHeaderSnapshot   = finalFromXFrame == 0 ? rightFakeHeaderSnapshot : leftFakeHeaderSnapshot;
            var fromFakeHeaderSnapshot = finalFromXFrame == 0 ? leftFakeHeaderSnapshot : rightFakeHeaderSnapshot;

            var headerToFrame   = toVC.View.ConvertRectToView(toFakeHeader.Frame, containerView);
            var headerFromFrame = toVC.View.ConvertRectToView(fromFakeHeader.Frame, containerView);

            toFakeHeaderSnapshot.Frame   = headerToFrame;
            fromFakeHeaderSnapshot.Frame = headerStartFrame;
            toHeaderSnapshot.Frame       = headerToFrame;
            toHeaderSnapshot.Alpha       = 0;

            containerView.AddSubview(toFakeHeaderSnapshot);
            containerView.AddSubview(fromFakeHeaderSnapshot);
            containerView.AddSubview(toHeaderSnapshot);
            containerView.AddSubview(fromHeaderSnapshot);

            //hide origin views
            //fromFakeHeaderSnapshot.alpha = 0
            toFakeHeader.Alpha      = 0;
            toVC.HeaderView.Alpha   = 0;
            toVC.Collection.Alpha   = 0;
            fromVC.HeaderView.Alpha = 0;
            fromVC.Collection.Alpha = 0;

            AnimationHelper.PerspectiveTransformForContainerView(containerView);
            var duration = TransitionDuration(transitionContext);

            UIView.AnimateKeyframes(duration, 0, UIViewKeyframeAnimationOptions.CalculationModeLinear, () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0.0, 0.25f, () =>
                {
                    toHeaderSnapshot.Alpha = 1;
                });

                UIView.AddKeyframeWithRelativeStartTime(0.1, 0.3f, () =>
                {
                    overlappedCells.ForEach((obj) => obj.Alpha = 0);
                });

                UIView.AddKeyframeWithRelativeStartTime(0, 1f, () =>
                {
                    fromHeaderSnapshot.Frame     = headerFromFrame;
                    fromFakeHeaderSnapshot.Frame = headerFromFrame;
                    toHeaderSnapshot.Frame       = headerFinalFrame;
                    toFakeHeaderSnapshot.Frame   = headerFinalFrame;


                    fromHeaderSnapshot.Alpha = 0.2f;
                    toHeaderSnapshot.Alpha   = 1;


                    fromFakeHeader.Transform = CGAffineTransform.MakeTranslation(headerStartFrame.GetMidX() - headerToFrame.GetMidX(), 0);

                    for (var i = 0; i < visibleToSnapshots.Count; i++)
                    {
                        var snapshot   = visibleToSnapshots[i];
                        snapshot.Frame = new CGRect(convertedFromCellCoords[i], new CGSize(cellSize[i].Width, cellSize[i].Height));
                        snapshot.Alpha = 1.0f;
                    }

                    foreach (var snapshot in visibleFromSnapshots)
                    {
                        snapshot.Frame = new CGRect(new CGPoint(snapshot.Frame.X, snapshot.Frame.Y),
                                                    new CGSize(snapshot.Frame.Width / 3, snapshot.Frame.Height / 2));
                        var finalX = this.finalFromXFrame;
                        if (finalX == UIScreen.MainScreen.Bounds.Width)
                        {
                            finalX -= snapshot.Frame.Width;
                        }
                        snapshot.Frame = new CGRect(new CGPoint(finalX, snapshot.Frame.Y + snapshot.Frame.Height / 2),
                                                    snapshot.Frame.Size);
                        snapshot.Alpha = 0;
                    }
                });

                UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25f, () =>
                {
                    fromHeaderSnapshot.Alpha = 0;
                });

                UIView.AddKeyframeWithRelativeStartTime(0.9, 0.1f, () =>
                {
                    toFakeHeader.Alpha = 1;
                });
            }, (bool finished) =>
            {
                fromFakeHeader.Transform   = CGAffineTransform.MakeIdentity();
                toVC.Collection.Alpha      = 1.0f;
                toVC.HeaderView.Alpha      = 1;
                toVC.LeftFakeHeader.Alpha  = 1;
                toVC.RightFakeHeader.Alpha = 1;

                foreach (var snap in visibleFromSnapshots)
                {
                    snap.RemoveFromSuperview();
                }
                foreach (var snap in visibleToSnapshots)
                {
                    snap.RemoveFromSuperview();
                }
                leftFakeHeaderSnapshot.RemoveFromSuperview();
                rightFakeHeaderSnapshot.RemoveFromSuperview();
                fromHeaderSnapshot.RemoveFromSuperview();
                toHeaderSnapshot.RemoveFromSuperview();
                fromVC.View.RemoveFromSuperview();
                transitionContext.CompleteTransition(!transitionContext.TransitionWasCancelled);
            });
        }
Esempio n. 14
0
        void AnimatePinStreaming(List <UILabel> images)
        {
            animationRunning = true;
            if (images.Count == 0)
            {
                animationRunning = false;

                return;
            }
            float duration = .8f;
            UIViewAnimationOptions opts = UIViewAnimationOptions.CurveEaseOut | UIViewAnimationOptions.Repeat;
            var image1 = images[0];
            var rand   = new Random();

            //var anim1 = new CoreAnimation.CAAnimation();

            UIView.AnimateKeyframes(duration * images.Count,
                                    delay: 0,
                                    options: UIViewKeyframeAnimationOptions.Repeat,
                                    animations: () =>
            {
                UIView.AddKeyframeWithRelativeStartTime(0, 0.15, () =>
                {
                    image1.Alpha = 1;
                });
                UIView.AddKeyframeWithRelativeStartTime(0, 0.25, () =>
                {
                    image1.Center = new CGPoint(image1.Center.X, image1.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                });

                UIView.AddKeyframeWithRelativeStartTime(0, 0.08, () =>
                {
                });


                UIView.AddKeyframeWithRelativeStartTime(0.225, 0.25, () =>
                {
                    image1.Alpha = 0;
                });



                if (images.Count > 1)
                {
                    var image2 = images[1];
                    UIView.AddKeyframeWithRelativeStartTime(0.25, 0.15, () =>
                    {
                        image2.Alpha = 1;
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.25, 0.25, () =>
                    {
                        image2.Center = new CGPoint(image2.Center.X, image2.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                    });

                    UIView.AddKeyframeWithRelativeStartTime(0.475, 0.25, () =>
                    {
                        image2.Alpha = 0;
                    });
                }

                if (images.Count > 2)
                {
                    var image3 = images[2];
                    UIView.AddKeyframeWithRelativeStartTime(0.5, 0.15, () =>
                    {
                        image3.Alpha = 1;
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.5, 0.25, () =>
                    {
                        image3.Center = new CGPoint(image3.Center.X, image3.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.725, 0.25, () =>
                    {
                        image3.Alpha = 0;
                    });
                }
                if (images.Count > 3)
                {
                    var image4 = images[3];
                    UIView.AddKeyframeWithRelativeStartTime(0.75, 0.15, () =>
                    {
                        image4.Alpha = 1;
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25, () =>
                    {
                        image4.Center = new CGPoint(image4.Center.X, image4.Center.Y - (1 + rand.NextDouble() % 0.5) * 60);
                    });
                    UIView.AddKeyframeWithRelativeStartTime(0.75, 0.25, () =>
                    {
                        image4.Alpha = 0;
                    });
                }
            }, completion: (i) =>
            {
            });

            animationRunning = false;
        }