UIScrollView inside UITableViewCell touch detect

后端 未结 5 1478
清歌不尽
清歌不尽 2020-12-04 20:16

I have a tableview with 8 custom cells. in the 8th cell I added a scrollView with paging enabled so I can show page 1 and page 2 (or 3, 4... 10) without have a very high cel

5条回答
  •  旧巷少年郎
    2020-12-04 20:26

    There is a trick Apple recommends to use in this case, in theirs WWDC 2014 session "Advanced scrollviews" (See Demo starting from 8:10):

    [cell.contentView addSubview:_scrollView];
    [_scrollView setUserInteractionEnabled:NO];
    [cell.contentView addGestureRecognizer:_scrollView.panGestureRecognizer];
    

    That's all what needs to be done, no need to override touchesBegan:, touchesMoved: and others.


    I used solution based on overriding of touchesBegan:, touchesMoved:, touchesEnded: and touchesCancelled: previously, but sometimes it caused a weird behaviour: when select a certain cell, method -tableView:didSelectRowAtIndexPath: was called for cell with different indexPath.

    Solution from Apple has no side effects so far and looks more elegant.

提交回复
热议问题