Exemple #1
0
        void LowerButtonAndFadeOutBackground()
        {
            if (IsRaised)
            {
                nfloat startRadius  = LiftedShadowRadius;
                nfloat startOpacity = LiftedShadowOpacity;
                CGPath startPath    = UIBezierPath.FromRoundedRect(UpRect, CornerRadius).CGPath;

                if (Layer.AnimationKeys != null && Layer.AnimationKeys.Length > 0)
                {
                    startRadius  = Layer.PresentationLayer.ShadowRadius;
                    startOpacity = Layer.PresentationLayer.ShadowOpacity;
                    startPath    = Layer.PresentationLayer.ShadowPath;
                }

                CABasicAnimation decreaseRadius = CABasicAnimation.FromKeyPath("shadowRadius");
                decreaseRadius.SetFrom(NSNumber.FromNFloat(startRadius));
                decreaseRadius.SetTo(NSNumber.FromNFloat(LoweredShadowRadius));
                decreaseRadius.Duration            = TouchUpAnimationDuration;
                decreaseRadius.FillMode            = CAFillMode.Forwards;
                decreaseRadius.RemovedOnCompletion = true;
                Layer.ShadowRadius = LoweredShadowRadius;

                CABasicAnimation shadowOpacityAnimation = CABasicAnimation.FromKeyPath("shadowOpacity");
                shadowOpacityAnimation.Duration = TouchUpAnimationDuration;
                shadowOpacityAnimation.SetFrom(NSNumber.FromNFloat(startOpacity));
                shadowOpacityAnimation.SetTo(NSNumber.FromNFloat(LoweredShadowOpacity));
                shadowOpacityAnimation.FillMode            = CAFillMode.Backwards;
                shadowOpacityAnimation.RemovedOnCompletion = true;
                Layer.ShadowOpacity = LoweredShadowOpacity;

                CABasicAnimation shadowAnimation = CABasicAnimation.FromKeyPath("shadowPath");
                shadowAnimation.Duration = TouchUpAnimationDuration;
                shadowAnimation.SetFrom(startPath);
                shadowAnimation.SetTo(UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath);
                shadowAnimation.FillMode            = CAFillMode.Forwards;
                shadowAnimation.RemovedOnCompletion = true;
                Layer.ShadowPath = UIBezierPath.FromRoundedRect(DownRect, CornerRadius).CGPath;


                Layer.AddAnimation(shadowAnimation, "shadow");
                Layer.AddAnimation(decreaseRadius, "shadowRadius");
                Layer.AddAnimation(shadowOpacityAnimation, "shadowOpacity");
            }

            if (IsColorClear(BackgroundColor))
            {
                nfloat startingOpacity = BackgroundColorFadeLayer.Opacity;

                if (BackgroundColorFadeLayer.AnimationKeys != null &&
                    BackgroundColorFadeLayer.AnimationKeys.Length > 0 &&
                    BackgroundColorFadeLayer.PresentationLayer != null)
                {
                    startingOpacity = BackgroundColorFadeLayer.PresentationLayer.Opacity;
                }

                CABasicAnimation removeFadeBackgroundDarker = CABasicAnimation.FromKeyPath("opacity");
                removeFadeBackgroundDarker.Duration       = TouchUpAnimationDuration;
                removeFadeBackgroundDarker.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                removeFadeBackgroundDarker.SetFrom(NSNumber.FromNFloat(startingOpacity));
                removeFadeBackgroundDarker.SetTo(NSNumber.FromNFloat(0));
                removeFadeBackgroundDarker.FillMode            = CAFillMode.Forwards;
                removeFadeBackgroundDarker.RemovedOnCompletion = !false;
                BackgroundColorFadeLayer.Opacity = 0;

                BackgroundColorFadeLayer.AddAnimation(removeFadeBackgroundDarker, "animateOpacity");
            }
        }
Exemple #2
0
        void FadeInBackgroundAndRippleTapCircle()
        {
            if (IsColorClear(BackgroundColor))
            {
                if (TapCircleColor == null)
                {
                    TapCircleColor = UsesSmartColor ? TitleLabel.TextColor.ColorWithAlpha(ClearBackgroundDumbTapCircleColor.CGColor.Alpha) : ClearBackgroundDumbTapCircleColor;
                }

                if (BackgroundFadeColor == null)
                {
                    BackgroundFadeColor = UsesSmartColor ? TitleLabel.TextColor.ColorWithAlpha(ClearBackgroundDumbFadeColor.CGColor.Alpha) : ClearBackgroundDumbFadeColor;
                }

                BackgroundColorFadeLayer.BackgroundColor = BackgroundFadeColor.CGColor;

                float startingOpacity = BackgroundColorFadeLayer.Opacity;

                if (BackgroundColorFadeLayer.AnimationKeys != null &&
                    BackgroundColorFadeLayer.AnimationKeys.Length > 0 &&
                    BackgroundColorFadeLayer.PresentationLayer != null)
                {
                    startingOpacity = BackgroundColorFadeLayer.PresentationLayer.Opacity;
                }

                CABasicAnimation fadeBackgroundDarker = CABasicAnimation.FromKeyPath("opacity");
                fadeBackgroundDarker.Duration       = TouchDownAnimationDuration;
                fadeBackgroundDarker.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
                fadeBackgroundDarker.SetFrom(NSNumber.FromNFloat(startingOpacity));
                fadeBackgroundDarker.SetTo(NSNumber.FromNFloat(1));
                fadeBackgroundDarker.FillMode            = CAFillMode.Forwards;
                fadeBackgroundDarker.RemovedOnCompletion = !false;
                BackgroundColorFadeLayer.Opacity         = 1;

                BackgroundColorFadeLayer.AddAnimation(fadeBackgroundDarker, "animateOpacity");
            }
            else
            {
                if (TapCircleColor == null)
                {
                    TapCircleColor = UsesSmartColor ? TitleLabel.TextColor.ColorWithAlpha(DumbTapCircleFillColor.CGColor.Alpha) : DumbTapCircleFillColor;
                }
            }

            nfloat tapCircleFinalDiameter = CalculateTapCircleFinalDiameter();

            var tapCircleLayerSizerView = new UIView(new CGRect(0, 0, tapCircleFinalDiameter, tapCircleFinalDiameter));

            tapCircleLayerSizerView.Center = RippleFromTapLocation ? TapPoint : new CGPoint(Bounds.GetMidX(), Bounds.GetMidY());

            var startingRectSizerView = new UIView(new CGRect(0, 0, TapCircleDiameterStartValue, TapCircleDiameterStartValue));

            startingRectSizerView.Center = tapCircleLayerSizerView.Center;

            UIBezierPath startingCirclePath = UIBezierPath.FromRoundedRect(startingRectSizerView.Frame, TapCircleDiameterStartValue / 2f);

            var endingRectSizerView = new UIView(new CGRect(0, 0, tapCircleFinalDiameter, tapCircleFinalDiameter));

            endingRectSizerView.Center = tapCircleLayerSizerView.Center;

            UIBezierPath endingCirclePath = UIBezierPath.FromRoundedRect(endingRectSizerView.Frame, tapCircleFinalDiameter / 2f);

            CAShapeLayer tapCircle = new CAShapeLayer();

            tapCircle.FillColor   = TapCircleColor.CGColor;
            tapCircle.StrokeColor = UIColor.Clear.CGColor;
            tapCircle.BorderColor = UIColor.Clear.CGColor;
            tapCircle.BorderWidth = 0;
            tapCircle.Path        = startingCirclePath.CGPath;

            if (!RippleBeyondBounds)
            {
                CAShapeLayer mask = new CAShapeLayer();
                mask.Path        = UIBezierPath.FromRoundedRect(FadeAndClippingMaskRect, CornerRadius).CGPath;
                mask.FillColor   = UIColor.Black.CGColor;
                mask.StrokeColor = UIColor.Clear.CGColor;
                mask.BorderColor = UIColor.Clear.CGColor;
                mask.BorderWidth = 0;

                tapCircle.Mask = mask;
            }

            RippleAnimationQueue.AddObjects(new NSObject[] { tapCircle });
            Layer.InsertSublayerAbove(tapCircle, BackgroundColorFadeLayer);

            CABasicAnimation tapCircleGrowthAnimation = CABasicAnimation.FromKeyPath("path");

            tapCircleGrowthAnimation.Duration       = TouchDownAnimationDuration;
            tapCircleGrowthAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
            tapCircleGrowthAnimation.SetFrom(startingCirclePath.CGPath);
            tapCircleGrowthAnimation.SetTo(endingCirclePath.CGPath);
            tapCircleGrowthAnimation.FillMode            = CAFillMode.Forwards;
            tapCircleGrowthAnimation.RemovedOnCompletion = false;

            CABasicAnimation fadeIn = CABasicAnimation.FromKeyPath("opacity");

            fadeIn.Duration       = TouchDownAnimationDuration;
            fadeIn.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear);
            fadeIn.SetFrom(NSNumber.FromNFloat(0));
            fadeIn.SetTo(NSNumber.FromNFloat(1));
            fadeIn.FillMode            = CAFillMode.Forwards;
            fadeIn.RemovedOnCompletion = false;

            tapCircle.AddAnimation(tapCircleGrowthAnimation, "animatePath");
            tapCircle.AddAnimation(fadeIn, "opacityAnimation");
        }