Swift UIScrollViewDelegate不会触发scrollViewDidScroll事件

时间:2015-12-15 06:39:46

标签: ios swift uiscrollview delegates uiscrollviewdelegate

我的UIScrollViews中有两个UIViewController,它们都有不同的属性,例如pagingEnabledcontentSize& contentInset我还需要它们在滚动时单独行动,所以我创建了两个单独的自定义类,如下所示。

class NavigationScrollView: UIScrollView{

}

class ContentScrollView: UIScrollView{

}

也代表

extension NavigationScrollView: UIScrollViewDelegate{
    // this method not triggers
    func scrollViewDidScroll(scrollView: UIScrollView) {

    }
}
extension ContentScrollView: UIScrollViewDelegate{
    // this method not triggers
    func scrollViewDidScroll(scrollView: UIScrollView) {

    }    
}

在主viewController viewDidLoad()我做

navigationScroller = NavigationScrollView(frame: CGRectMake(0.0, 0.0, frameWidth, 40.0))
contentScroller = ContentScrollView(frame: CGRectMake(0.0, 0.0, frameWidth, frameHeight))

1 个答案:

答案 0 :(得分:2)

你怎么用这种方式分配代表?

    class NavigationScrollView: UIScrollView{
        override func didMoveToSuperview() {
            super.didMoveToSuperview()
            self.delegate = self
        }
    }

    class ContentScrollView: UIScrollView{
        override func didMoveToSuperview() {
            super.didMoveToSuperview()
            self.delegate = self
        }
    }