【问题标题】:Identify the touch moved direction识别触摸移动方向
【发布时间】:2013-04-01 12:36:08
【问题描述】:

我正在进行视图调整大小、移动和旋转一次触摸。

我正在尝试找到触摸移动的方向,例如,

如果触摸移动的方向是水平或垂直,则移动视图。 如果触摸移动方向是对角线,则调整大小。 如果触摸像旋转手势一样移动,则旋转视图。

我能够识别水平或垂直方向。

请建议我如何识别对角线和旋转。

【问题讨论】:

    标签: ios objective-c touch


    【解决方案1】:

    我猜想旋转,你可以简单地使用这个方法-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

    对于对角线,您可以比较两个点的坐标。 对于对角线,您也可以从这个post 获得帮助。

    【讨论】:

    • 谢谢@Hinata 我会试试这个。
    【解决方案2】:

    试试这个:

    TDResizerView

    视图旋转和移动都可以在这个中使用

    【讨论】:

    • 实际上我正在尝试仅使用 1 个角。
    【解决方案3】:

    在触摸移动功能中,您可以像这样识别移动手指的方向。

    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
    {
      [super touchesMoved:touches withEvent:event]; 
       UITouch *touch = [touches anyObject];
       CGPoint current=[touch locationInView:self];
       CGPoint last=[touch previousLocationInView:self];
    
       if(current.x>last.x){
          NSLog(@">>>>rigth");
       }else{
         NSLog(@">>>>left");
       }
    
       if(current.y>last.y){
        NSLog(@">>>>up");
       }else{
        NSLog(@">>>>down");
       }   
    }
    

    【讨论】:

      猜你喜欢
      • 2023-03-04
      • 1970-01-01
      • 1970-01-01
      • 2017-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多