UISwipeGestureRecognizer Swipe length

后端 未结 6 2181
暗喜
暗喜 2020-12-01 00:53

Any idea if there is a way to get the length of a swipe gesture or the touches so that i can calculate the distance?

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-01 01:16

    For those of us using Xamarin:

    void panGesture(UIPanGestureRecognizer gestureRecognizer) {
        if (gestureRecognizer.State == UIGestureRecognizerState.Began) {
            startLocation = gestureRecognizer.TranslationInView (view)
        } else if (gestureRecognizer.State == UIGestureRecognizerState.Ended) {
            PointF stopLocation = gestureRecognizer.TranslationInView (view);
            float dX = stopLocation.X - startLocation.X;
            float dY = stopLocation.Y - startLocation.Y;
            float distance = Math.Sqrt(dX * dX + dY * dY);
            System.Console.WriteLine("Distance: {0}", distance);
        }
    }
    

提交回复
热议问题