简体   繁体   中英

iOS - UITapGestureRecognizer not fired from UIView inside UIScrollView inside UITableViewCell

I have a custom UIView subclass that has a UITapGestureRecognizer attached to it. I am trying to use this custom view inside of a UIView (container) inside of a UIScrollView, inside of a UITableViewCell.

So:

UITableViewCell

•UIScrollView

••UIView (container for proper contentSize on UIScrollView)

•••Bunch of UIViews with UITapGestureRecognizer (subclass)

It seems that if I don't use a 'container' view inside the UIScrollView, the taps get detected just fine. But then the contentSize is not correct and some of my custom views inside the UIScrollView are off screen and can't be accessed.

If I do use a 'container' view inside the UIScrollView, the contentSize for the scroll view is correct, but none of the custom view taps get detected.

I have tried all sorts of variations of the below with no success:

tapGesture.cancelsTouchesInView = false
scrollView.canCancelContentTouches = false
scrollView.userInteractionEnabled = true
containerView.userInteractionEnabled = true

Well I couldn't get it to work for some reason, even tried subclassing UIScrollView and the UIView for the container view.

I ended up just adding a UICollectionView to the subclassed UITableViewCell, and then setting the UITableViewController as the UICollectionViewDataSource and UICollectionViewDelegate to handle item selection.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM