【问题标题】:Xamarin iOS - UIView Animation with velocityXamarin iOS - 具有速度的 UIView 动画
【发布时间】:2017-08-08 07:45:19
【问题描述】:

我有一个 UIView 位于所有其他视图之上。这个 UIView 有一个 UIPanGestureRecognizer 可以在屏幕上拖动它。如果用户停止平移,视图将移动到计算出的位置,即左侧屏幕边界或右侧边界。这很好用,但现在我想考虑 View 在屏幕上移动的速度,当用户将手指从屏幕上抬起时,UIView 不应该立即停止移动到端点,而是应该用曲线来完成。

编辑 1

我认为我错误地表达了自己。我的意思是视图应该移动用户拖动它的方向,但它应该形成一条曲线并移动到所需的位置。把它想象成重力。用户将从左下角以一定速度拖动视图到屏幕中间并立即抬起手指。然后视图不应该停止,否则它应该在最后一个方向移动并慢慢移动到所需的位置,在这种情况下是右下角。

这是我已有的代码:

private void DidPan()
{
    CGPoint translation = PanGesture.TranslationInView(this.Superview);
    CGPoint velocity = PanGesture.VelocityInView(this.Superview);

    if (PanGesture.State == UIGestureRecognizerState.Changed)
    {
        this.Center = new CGPoint(lastLocation.X + translation.X, lastLocation.Y + translation.Y);
    }
    else if (PanGesture.State == UIGestureRecognizerState.Ended)
    {
        // Calculates the new position the view will be moving to
        var newLocation = new CGPoint(SetX(Superview.Bounds), SetY(Superview.Bounds));

        // Animate it to the desired location
        UIView.Animate(0.3, () =>
        {
            this.Center = newLocation;
        }, null);
    }
}

如您所见,我们已经有了速度,但我不知道如何从这里继续。希望有人从这里有正确的起点并可以帮助我。

非常感谢!

【问题讨论】:

    标签: ios animation uiview xamarin.ios uipangesturerecognizer


    【解决方案1】:

    我认为UIKit Dynamics可以满足你的要求。

    参考这个博客:https://blog.xamarin.com/drag-drop-and-snap-with-uikit-dynamics/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-10-23
      • 1970-01-01
      • 2013-07-04
      • 2021-05-24
      • 1970-01-01
      • 1970-01-01
      • 2012-01-19
      相关资源
      最近更新 更多