public void CreateArcAnimationForKey(string key, double fromValue, double toValue, CAAnimationDelegate @delegate) { var _fromValue = new NSNumber(fromValue); var _toValue = new NSNumber(toValue); var _key = new NSString(key); var arcAnimation = CABasicAnimation.FromKeyPath(key); var currentAngle = _fromValue; if (PresentationLayer != null) { currentAngle = (NSNumber)PresentationLayer.ValueForKey(_key); } arcAnimation.Duration = 1.0f; arcAnimation.From = currentAngle; arcAnimation.To = _toValue; arcAnimation.Delegate = @delegate; arcAnimation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Default); AddAnimation(arcAnimation, key); SetValueForKey(_toValue, _key); }
protected void Exit(bool animated, Action completionBlock) { base.Exit(animated); if (!animated) { RemoveAllAnimations(); CATransaction.Begin(); CATransaction.DisableActions = true; Opacity = 0; //__weak MDCLegacyInkLayerForegroundRipple * weakSelf = self; CATransaction.CompletionBlock = new Action(() => { this.RemoveFromSuperLayer(); if (this.animationDelegate != null) { animationDelegate.AnimationDidStop(null, this, true); } }); CATransaction.Commit(); return; } if (Bounded) { ForegroundOpacityAnim.Values = new NSNumber[] { 1, 0 }; ForegroundOpacityAnim.Duration = kInkLayerForegroundBoundedOpacityExitDuration; // Bounded ripples move slightly towards the center of the tap target. Unbounded ripples // move to the center of the tap target. nfloat xOffset = (nfloat)(TargetFrame.X - InkLayer?.Frame.X); nfloat yOffset = (nfloat)(TargetFrame.Y - InkLayer?.Frame.Y); CGPoint startPoint = new CGPoint(Point.X + xOffset, Point.Y + yOffset); CGPoint endPoint = MDCLegacyInkLayerRectGetCenter(TargetFrame); if (UseCustomInkCenter) { endPoint = new CGPoint(CustomInkCenter, CustomInkCenter); } endPoint = new CGPoint(endPoint.X + xOffset, endPoint.Y + yOffset); CGPoint centerOffsetPoint = MDCLegacyInkLayerInterpolatePoint(startPoint, endPoint, 0.3f); UIBezierPath movePath = new UIBezierPath(); movePath.MoveTo(startPoint); movePath.AddLineTo(centerOffsetPoint); ForegroundPositionAnim = PositionAnimWithPath(movePath.CGPath, duration: kInkLayerForegroundBoundedPositionExitDuration, timingFunction: LogDecelerateEasing()); ForegroundScaleAnim.Values = new NSNumber[] { 0, 1 }; ForegroundScaleAnim.KeyTimes = new NSNumber[] { 0, 1 }; ForegroundScaleAnim.Duration = kInkLayerForegroundBoundedRadiusExitDuration; } else { NSNumber opacityVal = (NSNumber)PresentationLayer.ValueForKey((NSString)kInkLayerOpacity); if (opacityVal == null) { opacityVal = NSNumber.FromFloat(0.0f); } nfloat adjustedDuration = kInkLayerForegroundBoundedPositionExitDuration; nfloat normOpacityVal = opacityVal.FloatValue; nfloat opacityDuration = normOpacityVal / 3.0f; ForegroundOpacityAnim.Values = new NSNumber[] { opacityVal, 0 }; ForegroundOpacityAnim.Duration = opacityDuration + adjustedDuration; NSNumber scaleVal = (NSNumber)PresentationLayer.ValueForKey((NSString)kInkLayerScale); if (scaleVal == null) { scaleVal = NSNumber.FromFloat(0.0f); } nfloat unboundedDuration = (nfloat)Math.Sqrt(((1.0f - scaleVal.FloatValue) * Radius) / (kInkLayerForegroundWaveTouchDownAcceleration + kInkLayerForegroundWaveTouchUpAcceleration)); ForegroundPositionAnim.Duration = unboundedDuration + adjustedDuration; ForegroundScaleAnim.Values = new NSNumber[] { scaleVal, 1 }; ForegroundScaleAnim.Duration = unboundedDuration + adjustedDuration; } ForegroundOpacityAnim.KeyTimes = new NSNumber[] { 0, 1 }; if (ForegroundOpacityAnim.Duration < ForegroundScaleAnim.Duration) { ForegroundScaleAnim.Delegate = this; } else { ForegroundOpacityAnim.Delegate = this; } ForegroundOpacityAnim.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.Linear); ForegroundPositionAnim.TimingFunction = LogDecelerateEasing(); ForegroundScaleAnim.TimingFunction = LogDecelerateEasing(); CATransaction.Begin(); if (completionBlock != null) { CATransaction.CompletionBlock = new Action(() => { if (RippleState != MDCInkRippleState.kInkRippleCancelled) { completionBlock(); } }); } AddAnimation(ForegroundOpacityAnim, kInkLayerForegroundOpacityAnim); AddAnimation(ForegroundPositionAnim, kInkLayerForegroundPositionAnim); AddAnimation(ForegroundScaleAnim, kInkLayerForegroundScaleAnim); CATransaction.Commit(); }