上下滚动时增加或减

上下滚动时增加或减

上下滚动时增加或减小imageView的高度

extension DetailViewController: UIScrollViewDelegate {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {


            if (self.lastContentOffset > scrollView.contentOffset.y) {
                UIView.animate(withDuration: 0.2, animations: {
                    print("going down")
                    if self.imgViewHeight.constant >= 200 {
                        self.blurView.alpha = 0

                        self.backButton.isHidden = false
                    }
                    else if self.imgViewHeight.constant <= 200{
                        self.blurView.alpha = 1


                        self.imgViewHeight.constant = self.imgViewHeight.constant + 4

                    }
                }, completion: nil)

            }
            else if (self.lastContentOffset < scrollView.contentOffset.y) {

                UIView.animate(withDuration: 0.2, animations: {
                    if self.imgViewHeight.constant <= 72 {
                       self.blurView.alpha = 1
                        self.backButton.isHidden = false
                        self.descriptions.isScrollEnabled = true
                    }
                    else if self.imgViewHeight.constant >= 72{
                        self.blurView.alpha = 1

                        self.imgViewHeight.constant = self.imgViewHeight.constant - 4

                    }

                    print("lolol:\(self.imgViewHeight.constant)")

                }, completion: nil)

            }
            else {

            }

            self.lastContentOffset = scrollView.contentOffset.y
        }
}

最佳答案

您可以使用ScrollView函数,例如:

func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
//your code when you want start scrolling

}

func scrollViewWillEndDragging(_ scrollView: UIScrollView) {
//your code when you want run after stop scrolling

}

关于swift - 上下滚动时增加或减少imageView的高度,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/56287511/

10-09 16:19