ios实现任意方向任意角度的UISwipeGestureRecogniser

标签 ios uigesturerecognizer implementation gesture direction

我试图在左下位置(意味着在左下之间)滑动东西。但是 UISwipeGesture 只能识别左、右、下和上。

我想在我的整个屏幕 View 上添加手势。然后,每当用户在屏幕上滑动时,我想知道滑动的起始坐标和结束坐标。滑动可以在任何角度和任何位置。有没有办法在iOS中获取滑动的开始和结束坐标

请帮帮我。我被严重卡住了。提前致谢。

最佳答案

现在我通过以下步骤完成了这个实现:-

您可以在扩展类“UIGestureRecognizer”后实现一些委托(delegate)方法。

这是方法。

//会给出触摸的起点

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
 CGPoint startSwipePoint= [touches.anyObject locationInView:self.view];
}

//会定时给出触摸点

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
 CGPoint point=[touches.anyObject locationInView:self.view];
}

//它会给出结束滑动点

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{  
    CGPoint endSwipePoint= [touches.anyObject locationInView:self.view];
}

//这里是计算两点之间角度的代码。我正在使用起点和终点。但是你可以根据你的要求使用任何两个点

CGFloat angle=atan2(startSwipePoint.y - endSwipePoint.y, endSwipePoint.x - startSwipePoint.x) * Rad2Deg;

关于ios实现任意方向任意角度的UISwipeGestureRecogniser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18464508/

相关文章:

ios - 识别对 iOS 中以编程方式创建的 UIView 子类的触摸

ios - 将导航标题设置为 2 个字符串

ios - 使用自定义颜色设置渐变

ios - 如何拖动和关闭 View Controller ?

ios - XCode 7.3 和 Swift 2.2 中没有这样的模块 'Alamofire'

iphone - 如何从 UIImageView 获取全分辨率的旋转、缩放和平移图像?

iphone - UIGestureRecognizer 在 UIScrollView 减速期间未接收到触摸

instagram 等应用程序的数据库实现

byte - crc16实现java

c++ - 链表的几种实现——C++