UIButton touch is delayed when in UIScrollView

前端 未结 7 1562
遥遥无期
遥遥无期 2020-11-30 19:01

I\'m running into a small issue in my app.

I essentially have a series of UIButtons added as subviews in a UIScrollView which is part of a

7条回答
  •  孤街浪徒
    2020-11-30 19:23

    In Swift 3:

    import UIKit
    
    class ScrollViewWithButtons: UIScrollView {
    
        override init(frame: CGRect) {
            super.init(frame: frame)
            myInit()
        }
    
        required init?(coder aDecoder: NSCoder) {
            super.init(coder: aDecoder)
            myInit()
        }
    
        private func myInit() {
            self.delaysContentTouches = false
        }
    
        override func touchesShouldCancel(in view: UIView) -> Bool {
            if view is UIButton {
                return true
            }
            return super.touchesShouldCancel(in: view)
        }
    }
    

    You can then use this ScrollViewWithButtons in IB or in code.

提交回复
热议问题