vnt*_*udy 5 implementation direction gesture uigesturerecognizer ios
我试图在左下位置(左右之间的平均值)滑动东西.但UISwipeGesture仅识别左,右,下和上.
我想在我的整个屏幕视图上添加手势.然后,每当用户在屏幕上滑动时,我想知道滑动的起始和终止坐标.滑动可以是任何角度和任何位置.有没有办法在iOS中获得滑动的起点和终点坐标
请帮我.我被困住了.Thanx提前.
现在我通过以下步骤完成了这个实现:-
您可以在扩展“UIGestureRecognizer”类后实现一些委托方法。
以下是方法。
// 它将给出触摸的起点
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint startSwipePoint= [touches.anyObject locationInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)
// 它将定期给出触摸点
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint point=[touches.anyObject locationInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)
//它将给出结束滑动点
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint endSwipePoint= [touches.anyObject locationInView:self.view];
}
Run Code Online (Sandbox Code Playgroud)
// 这是计算两点之间角度的代码。我正在使用起点和终点。但您可以根据您的要求使用这两点中的任何一个
CGFloat angle=atan2(startSwipePoint.y - endSwipePoint.y, endSwipePoint.x - startSwipePoint.x) * Rad2Deg;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
814 次 |
| 最近记录: |