我试图在左下位置(意味着在左下之间)滑动东西。但是 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/