Overriding delegate property of UIScrollView in Swift (like UICollectionView does)

后端 未结 6 2085
春和景丽
春和景丽 2021-02-01 02:36

UIScrollView has a delegate property which conforms to UIScrollViewDelegate

protocol UIScrollViewDelegate : NSObjectProtocol {
    //...
}
class UIScrollView : U         


        
6条回答
  •  遥遥无期
    2021-02-01 02:51

    You can do like this:

    protocol ExtendedUIScrollViewDelegate: UIScrollViewDelegate {
        func someNewFunction()
    }
    
    class CustomScrollView: UIScrollView {
    
        weak var myDelegate: ExtendedScrollViewDelegate?
        override weak var delegate: UIScrollViewDelegate? {
            didSet {
                myDelegate = delegate as? ExtendedScrollViewDelegate
            }
        }
    }
    

    Hope this helps

提交回复
热议问题