代码之家  ›  专栏  ›  技术社区  ›  Daniel Murali

uiTableView取消移动

  •  1
  • Daniel Murali  · 技术社区  · 14 年前

    我希望uiTableView的行为与userInteractionEnabled==no类似(该表应该停止被用户移动)。但我希望能够在用户移动uiTableView时激活它。

    如果我只是设置

    [self.tableView setUserInteractionEnabled:NO];
    

    此行为将在用户停止触摸后激活。

    我知道如何完成它吗?

    2 回复  |  直到 14 年前
        1
  •  0
  •   charlie hwang    14 年前

    您可以子类UITableView并重写ToucheSended:WithEvent:。当用户举起手指时,这个方法会受到攻击。由于您可能不想在用户点击屏幕时禁用用户交互,因此您可以捕获初始触摸起点和触摸终点。从这两个方面,您可以比较y的增量,以确定在禁用用户交互之前希望用户移动多少。这里有一些代码可以帮助您一路前进。

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch * touch = [touches anyObject];
      touchStartPoint = [touch locationInView:self];
    }
    
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
      UITouch * touch = [touches anyObject];
      CGPoint touchEndPoint = [touch locationInView:self];
      CGFloat deltaY = touchStartPoint.y - touchEndPoint.y;
    
      if (fabsf(deltaY) >= kMinimumYMoved) {
          self.userInteractionEnabled = NO;
      }
    }
    
        2
  •  0
  •   Daniel Murali    14 年前

    我知道怎么做了,真不敢相信我错过了这片土地:

    [myTableView setScrollEnabled:NO];