首页 > 代码库 > 触控手势算法

触控手势算法

        protected virtual GestureType GetTranslateGestureType(double xOffset, double yOffset, double xyOffset, double minOffset)
        {
            if (Math.Abs(xOffset) < minOffset && Math.Abs(yOffset) < minOffset) return GestureType.None;

            if (xOffset / xyOffset < Math.Cos(165.0 * Math.PI / 180.0))
                return GestureType.MoveLeft;
            if (xOffset / xyOffset > Math.Cos(15.0 * Math.PI / 180.0))
                return GestureType.MoveRight;
            if (-yOffset / xyOffset > Math.Sin(75.0 * Math.PI / 180.0))
                return GestureType.MoveTop;
            if (-yOffset / xyOffset < Math.Sin(-75.0 * Math.PI / 180.0))
                return GestureType.MoveBottom;

            if (xOffset / xyOffset < Math.Cos(120.0 * Math.PI / 180.0) && xOffset / xyOffset > Math.Cos(150.0 * Math.PI / 180.0)
                && -yOffset / xyOffset < Math.Sin(120.0 * Math.PI / 180) && -yOffset / xyOffset > Math.Sin(150.0 * Math.PI / 180.0))
                return GestureType.MoveLeftTop;
            if (xOffset / xyOffset < Math.Cos(240.0 * Math.PI / 180.0) && xOffset / xyOffset > Math.Cos(210.0 * Math.PI / 180.0)
                && -yOffset / xyOffset < Math.Sin(210.0 * Math.PI / 180) && -yOffset / xyOffset > Math.Sin(240.0 * Math.PI / 180.0))
                return GestureType.MoveLeftBottom;
            if (xOffset / xyOffset < Math.Cos(30.0 * Math.PI / 180.0) && xOffset / xyOffset > Math.Cos(60.0 * Math.PI / 180.0)
                && -yOffset / xyOffset > Math.Sin(30.0 * Math.PI / 180.0) && -yOffset / xyOffset < Math.Sin(60.0 * Math.PI / 180.0))
                return GestureType.MoveRightTop;
            if (xOffset / xyOffset < Math.Cos(-30.0 * Math.PI / 180.0) && xOffset / xyOffset > Math.Cos(-60.0 * Math.PI / 180.0)
                && -yOffset / xyOffset > Math.Sin(-60.0 * Math.PI / 180.0) && -yOffset / xyOffset < Math.Sin(-30.0 * Math.PI / 180.0))
                return GestureType.MoveRightBottom;

            return GestureType.None;
        }