UIButton does not work when it in UIScrollView

后端 未结 8 503
说谎
说谎 2020-12-01 10:38

My structure of views:

UITableView
  UITableViewCell
    UIScrollView
      CustomView
        UIButton

The problem is UIButton doesn\'t wo

8条回答
  •  孤街浪徒
    2020-12-01 11:17

    Create a subclass of UIScrollview with

    - (BOOL)touchesShouldCancelInContentView:(UIView *)view {
      return NO;
    }
    

    If you are not getting that message, set:

    scrollView.delaysContentTouches = NO;
    

    The problem is because of the way touchesShouldCancelInContentView behaves by default, it returns NO only if the subview is an UIControl, but your button is hidden inside the CustomView which isn't.

提交回复
热议问题