увеличить или уменьшить высоту imageView при прокрутке вверх или вниз - PullRequest
0 голосов
/ 24 мая 2019

увеличение или уменьшение высоты 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
        }
}

Ответы [ 3 ]

0 голосов
/ 24 мая 2019

Вам нужно позвонить layoutIfNeeded() на view в UIView.animate(withDuration:animations:) animations closure после установки значения imgViewHeight.constant.

extension DetailViewController: UIScrollViewDelegate {
    func scrollViewDidScroll(_ scrollView: UIScrollView) {
        if (self.lastContentOffset > scrollView.contentOffset.y) {
            UIView.animate(withDuration: 0.2) {[weak self] in
                self?.imgViewHeight.constant = 20 //This is just an example
                self?.view.layoutIfNeeded() //Here..........
            }
        }
        else if (self.lastContentOffset < scrollView.contentOffset.y) {
            UIView.animate(withDuration: 0.2) {[weak self] in
                self?.imgViewHeight.constant = 0 //This is just an example
                self?.view.layoutIfNeeded() //Here..........
            }
        }
        //Rest of the code...
    }
}

В приведенном выше коде я использовал примеры значений height constraint (20 and 0). Вместо этого добавьте свою собственную логику height.

0 голосов
/ 24 мая 2019

Привет, спасибо за помощь и ответ. я использовал MGCollapsingHeader pod

0 голосов
/ 24 мая 2019

Вы можете использовать функции 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

}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...