UIPangestureRecognizer

UIPangestureRecognizer

本文介绍了在Swift中获取UIPanGestureRecognizer的起点和终点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中使用UIPanGestureRecognizer,我想确定起点和终点.

I'm using UIPanGestureRecognizer on a project, and I want to take the starting point and the end point.

我尝试为touchesBegin做,但是没有得到满足我需要的代码.

I tried to do for touchesBegin, but did not get a code that does what I need.

如何获取UIPanGestureRecognizer的起点和终点?

How can I get the start point and end point of the UIPanGestureRecognizer?

推荐答案

对于您的情况,您可能希望将函数内部的代码包含在panGesture的IBAction中.在这里,我创建了一个视图,但是否则,您将只引用self.view而不是view.

For your case, you might want to include the code inside my function into your IBAction for the panGesture. Here I've created a view, but otherwise you would just be referring to self.view instead of view.

var view = UIView()

func panGestureMoveAround(gesture: UIPanGestureRecognizer) {

 var locationOfBeganTap: CGPoint

 var locationOfEndTap: CGPoint

 if gesture.state == UIGestureRecognizerState.Began {

     locationOfBeganTap = gesture.locationInView(view)

 } else if gesture.state == UIGestureRecognizerState.Ended {

    locationOfEndTap = gesture.locationInView(view)
 }

}

这篇关于在Swift中获取UIPanGestureRecognizer的起点和终点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-14 13:50