在滚动之前启动时调用scrollViewDidScroll

时间:2018-07-23 11:28:48

标签: ios swift xcode uiscrollview

我正在使用

它有containerview,这是scrollview,子viewController将显示在...中。

正在尝试在用户滚动视图时更改视图的高度。.

override func scrollViewDidScroll(_ scrollView: UIScrollView) {
    self.homeimg.image = UIImage(named: "smalllogo")
    self.imageheight.constant = 116
    UIView.animate(withDuration: 0.3, animations:{ self.view.layoutIfNeeded()})
}

这完全可以满足我的需要。.问题是containerview在启动时就被滚动了..因此,即使在滚动或触摸任何东西之前,也要在启动后立即调用它。 / p>

该如何解决?并仅在滚动或触摸时才进行更改吗?

1 个答案:

答案 0 :(得分:0)

你能试试吗

var viewAppeard = false

override func viewDidAppear(_ animated: Bool) {
    super.viewDidAppear(animated)
    viewAppeard = true
}

override func scrollViewDidScroll(_ scrollView: UIScrollView) {

    if viewAppeard {

        self.homeimg.image = UIImage(named: "smalllogo")
        self.imageheight.constant = 116
        UIView.animate(withDuration: 0.3, animations:{ self.view.layoutIfNeeded()})

    }

}