shouldReceiveTouch on UITableViewCellContentView

后端 未结 5 534
清歌不尽
清歌不尽 2020-12-31 07:27

I\'m trying to ignore UITapGestureRecognizer taps on a UITableView with the following:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer sho         


        
5条回答
  •  北荒
    北荒 (楼主)
    2020-12-31 07:51

    I've just came across this problem, and the following solution works on all iOS versions, without having the risk of Apple changing the view hierarchy of the tableView. Basicaly, keep a reference to your UITableView:

     - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
          if([touch.view isDescendantOfView:detailsTableView]) {
              return NO;
          }
          return YES;
       }
    
    //isDescendantOfView:YES if the receiver is an immediate or distant subview of view or if view is the receiver itself; otherwise NO.
    

提交回复
热议问题