Forward touches to a UIScrollView

后端 未结 4 1281
一个人的身影
一个人的身影 2021-01-04 08:32

I have two view controllers. View controller A has a UIScrollView and presents view controller B. The presentation is interactive and controlled by the sc

4条回答
  •  隐瞒了意图╮
    2021-01-04 09:17

    I have a scrollview inside of a superview to have left and right borders. To make those borders scrollable, this were my approach :

    class CustomScrollView: UIScrollView {
      override func hitTest(point: CGPoint, withEvent event: UIEvent?) -> UIView? {
        if let view = super.hitTest(point, withEvent: event) {
          return view
        }
    
        guard let superview = superview else {
          return nil
        }
    
        return superview.hitTest(superview.convertPoint(point, fromView: self), withEvent: event)
      }
    
      override func pointInside(point: CGPoint, withEvent event: UIEvent?) -> Bool {
        if super.pointInside(point, withEvent: event) {
          return true
        }
    
        guard let superview = superview else {
          return false
        }
    
        return superview.pointInside(superview.convertPoint(point, fromView: self), withEvent: event)
      }
    }
    

    Works perfectly

提交回复
热议问题