UIButton inside UITableViewCell steals touch from UITableView

前端 未结 4 703
终归单人心
终归单人心 2021-02-14 21:14

I have a problem similar to this one but answer provided there doesn\'t help much. I have UITableView with some custom UITableViewCells, those cells ha

4条回答
  •  [愿得一人]
    2021-02-14 21:37

    This is the standard behaviour of UIScrollView which tableviews use. The system doesn't know that you want to scroll until you move your finger, but by that time you have already "pressed" on the button and so it assumes that's what you want to do.

    You can play with a couple of properties on your tableview's scrollview to change the behaviour, but you may find they negatively impact the feel of your cells and buttons because of added delays.

    self.tableView.delaysContentTouches = YES;
    

    delaysContentTouches If the value of this property is YES, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent...

    and

    self.tableView.canCancelContentTouches = YES
    

    canCancelContentTouches If the value of this property is YES and a view in the content has begun tracking a finger touching it, and if the user drags the finger enough to initiate a scroll, the view receives a touchesCancelled:withEvent: message and the scroll view handles the touch as a scroll.

提交回复
热议问题