//Override Decelerating for Picker feature. protected override void Decelerating(float velocity, Animation animation) { //Reduce Scroll animation speed. //The picker is to select items in the scroll area, it is not correct to animate //the scroll with very high speed. velocity *= 0.5f; velocityOfLastPan = Math.Abs(velocity); float currentScrollPosition = -ContentContainer.PositionY; panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate); panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta; float destination = -(panAnimationDelta + currentScrollPosition); //Animation destination has to center of the item. float align = destination % itemHeight; destination -= align; destination -= startScrollOffset; float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination); float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : 0; float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0; if (destination < -maxPosition || destination > minPosition) { panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition); destination = velocity > 0 ? minPosition : -maxPosition; destination = -maxPosition + itemHeight; if (panAnimationDelta == 0) { panAnimationDuration = 0.0f; } else { panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate); } } else { panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration; if (adjustDestination != destination) { destination = adjustDestination; panAnimationDelta = destination + currentScrollPosition; velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1)); panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration; } } customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction); animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction); animation.Duration = (int)panAnimationDuration; animation.AnimateTo(ContentContainer, "PositionY", (int)destination); animation.Play(); }
//Override Decelerating for Picker feature. protected override void Decelerating(float velocity, Animation animation) { velocityOfLastPan = Math.Abs(velocity); float currentScrollPosition = -(ScrollingDirection == Direction.Horizontal ? ContentContainer.CurrentPosition.X : ContentContainer.CurrentPosition.Y); panAnimationDelta = (velocityOfLastPan * decelerationRate) / (1 - decelerationRate); panAnimationDelta = velocity > 0 ? -panAnimationDelta : panAnimationDelta; float destination = -(panAnimationDelta + currentScrollPosition); //Animation destination has to center of the item. float align = destination % itemHeight; destination -= align; destination -= startScrollOffset; float adjustDestination = AdjustTargetPositionOfScrollAnimation(destination); float maxPosition = ScrollAvailableArea != null ? ScrollAvailableArea.Y : 0; float minPosition = ScrollAvailableArea != null ? ScrollAvailableArea.X : 0; if (destination < -maxPosition || destination > minPosition) { panAnimationDelta = velocity > 0 ? (currentScrollPosition - minPosition) : (maxPosition - currentScrollPosition); destination = velocity > 0 ? minPosition : -maxPosition; destination = -maxPosition + itemHeight; if (panAnimationDelta == 0) { panAnimationDuration = 0.0f; } else { panAnimationDuration = (float)Math.Log((panAnimationDelta * logValueOfDeceleration / velocityOfLastPan + 1), decelerationRate); } } else { panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration; if (adjustDestination != destination) { destination = adjustDestination; panAnimationDelta = destination + currentScrollPosition; velocityOfLastPan = Math.Abs(panAnimationDelta * logValueOfDeceleration / ((float)Math.Pow(decelerationRate, panAnimationDuration) - 1)); panAnimationDuration = (float)Math.Log(-DecelerationThreshold * logValueOfDeceleration / velocityOfLastPan) / logValueOfDeceleration; } } customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction); animation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction); animation.Duration = (int)panAnimationDuration; animation.AnimateTo(ContentContainer, (ScrollingDirection == Direction.Horizontal) ? "PositionX" : "PositionY", (int)destination); animation.Play(); }
public void Initialize() { Log("Initialize() is called!"); Window window = Window.Instance; window.BackgroundColor = Color.White; window.TouchEvent += OnWindowTouched; window.TouchEvent += OnWindowTouched2; //window.EventProcessingFinished += OnEventProcessingFinished; window.WheelEvent += OnWindowWheelEvent; // Add a _text label to the window _text = new TextLabel("Hello Mono World"); _text.ParentOrigin = ParentOrigin.BottomCenter; _text.PivotPoint = PivotPoint.BottomCenter; _text.HorizontalAlignment = HorizontalAlignment.Center; _text.PointSize = 32.0f; window.Add(_text); _view1 = new View(); _view1.Size2D = new Size2D(200, 200); _view1.BackgroundColor = Color.Green; _view1.ParentOrigin = ParentOrigin.Center; _view1.PivotPoint = PivotPoint.Center; _view1.WidthResizePolicy = ResizePolicyType.Fixed; _view1.HeightResizePolicy = ResizePolicyType.Fixed; _view1.AddedToWindow += OnWindow; window.Add(_view1); _view2 = new View(); _view2.BackgroundColor = Color.Red; _view2.Size2D = new Size2D(50, 50); _view2.ParentOrigin = ParentOrigin.TopLeft; _view2.PivotPoint = PivotPoint.TopLeft; _view2.WidthResizePolicy = ResizePolicyType.Fixed; _view2.HeightResizePolicy = ResizePolicyType.Fixed; _view1.Add(_view2); _view3 = new View(); _view3.BackgroundColor = Color.Blue; _view3.Size2D = new Size2D(50, 50); _view3.ParentOrigin = ParentOrigin.TopLeft; _view3.PivotPoint = PivotPoint.TopLeft; _view3.WidthResizePolicy = ResizePolicyType.Fixed; _view3.HeightResizePolicy = ResizePolicyType.Fixed; _view1.Add(_view3); _user_alpha_func = new UserAlphaFunctionDelegate(body); MyAnimating(); }
// set decelerating properties // in this example, we used decelerate animation in "https://medium.com/@esskeetit/scrolling-mechanics-of-uiscrollview-142adee1142c" // But, if this method is problematic or violate some patent of other company, change this other way. // We didn't checked anything. // Only thing we need to remember when we change this animation is to add "EasingAnimationFinishedCallback" for the new animation. private void Decelerating(float lastVelocity) { absoluteVelocity = Math.Abs(lastVelocity); finishAnimationDelta = (absoluteVelocity * decelerationRate) / (1 - decelerationRate); float destination = (lastVelocity > 0) ? controlView.Position.X + finishAnimationDelta : controlView.Position.X - finishAnimationDelta; if (destination < leftDirectionLimit || destination > rightDirectionLimit) { finishAnimationDelta = lastVelocity > 0 ? (rightDirectionLimit - controlView.Position.X) : (controlView.Position.X - leftDirectionLimit); destination = lastVelocity > 0 ? rightDirectionLimit : leftDirectionLimit; if (finishAnimationDelta == 0) { finishAnimationDuration = 0.0f; } else { finishAnimationDuration = (float)Math.Log((finishAnimationDelta * logDeceleration / absoluteVelocity + 1), decelerationRate); } } else { if (finishAnimationDelta == 0) { finishAnimationDuration = 0.0f; } else { finishAnimationDuration = (float)Math.Log(-easingThreshold * logDeceleration / absoluteVelocity) / logDeceleration; } } finishAnimation.Clear(); customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction); finishAnimation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction); GC.KeepAlive(customScrollAlphaFunction); finishAnimation.Duration = (int)finishAnimationDuration; finishAnimation.AnimateTo(controlView, "PositionX", destination); finishAnimation.Play(); }
// set decelerating properties // in this example, we used decelerate animation in "https://medium.com/@esskeetit/scrolling-mechanics-of-uiscrollview-142adee1142c" // But, if this method is problematic or violate some patent of other company, change this other way. // We didn't checked anything. // Only thing we need to remember when we change this animation is to add "EasingAnimationFinishedCallback" for the new animation. private void Decelerating(float velocity) { mAbsoluteVelocity = Math.Abs(velocity); mFinishAnimationDelta = (mAbsoluteVelocity * mDecelerationRate) / (1 - mDecelerationRate); float destination = (velocity > 0) ? mControlView.Position.X + mFinishAnimationDelta : mControlView.Position.X - mFinishAnimationDelta; if (destination < mLeftDirectionLimit || destination > mRightDirectionLimit) { mFinishAnimationDelta = velocity > 0 ? (mRightDirectionLimit - mControlView.Position.X) : (mControlView.Position.X - mLeftDirectionLimit); destination = velocity > 0 ? mRightDirectionLimit : mLeftDirectionLimit; if (mFinishAnimationDelta == 0) { mFinishAnimationDuration = 0.0f; } else { mFinishAnimationDuration = (float)Math.Log((mFinishAnimationDelta * mLogDeceleration / mAbsoluteVelocity + 1), mDecelerationRate); } } else { if (mFinishAnimationDelta == 0) { mFinishAnimationDuration = 0.0f; } else { mFinishAnimationDuration = (float)Math.Log(-mEasingThreshold * mLogDeceleration / mAbsoluteVelocity) / mLogDeceleration; } } mFinishAnimation.Clear(); customScrollAlphaFunction = new UserAlphaFunctionDelegate(CustomScrollAlphaFunction); mFinishAnimation.DefaultAlphaFunction = new AlphaFunction(customScrollAlphaFunction); GC.KeepAlive(customScrollAlphaFunction); mFinishAnimation.Duration = (int)mFinishAnimationDuration; mFinishAnimation.AnimateTo(mControlView, "PositionX", destination); mFinishAnimation.Play(); }