コード例 #1
0
        void BurstTapCircle()
        {
            nfloat tapCircleFinalDiameter = CalculateTapCircleFinalDiameter();

            tapCircleFinalDiameter += TapCircleBurstAmount;

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

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

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

            CAShapeLayer tapCircle = (RippleAnimationQueue.Count > 0) ? RippleAnimationQueue.GetItem <CAShapeLayer>(0) : null;

            if (tapCircle != null)
            {
                if (RippleAnimationQueue.Count > 0)
                {
                    RippleAnimationQueue.RemoveObject(0);
                }
                DeathRowForCircleLayers.AddObjects(new NSObject[] { tapCircle });

                CGPath startingPath    = tapCircle.Path;
                nfloat startingOpacity = tapCircle.Opacity;

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

                CABasicAnimation tapCircleGrowthAnimation = CABasicAnimation.FromKeyPath("path");
                tapCircleGrowthAnimation.Duration       = TouchUpAnimationDuration;
                tapCircleGrowthAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseOut);
                tapCircleGrowthAnimation.SetFrom(startingPath);
                tapCircleGrowthAnimation.SetTo(endingCirclePath.CGPath);
                tapCircleGrowthAnimation.FillMode            = CAFillMode.Forwards;
                tapCircleGrowthAnimation.RemovedOnCompletion = false;

                CABasicAnimation fadeOut = CABasicAnimation.FromKeyPath("opacity");
                fadeOut.SetValueForKey(new NSString("fadeCircleOut"), new NSString("id"));
                fadeOut.SetFrom(NSNumber.FromNFloat(startingOpacity));
                fadeOut.SetTo(NSNumber.FromNFloat(0f));
                fadeOut.Duration            = TouchUpAnimationDuration;
                fadeOut.FillMode            = CAFillMode.Forwards;
                fadeOut.RemovedOnCompletion = false;

                tapCircle.AddAnimation(tapCircleGrowthAnimation, "animatePath");
                tapCircle.AddAnimation(fadeOut, "opacityAnimation");
            }
        }
コード例 #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");
        }