From 99fa1ae6863d6f46838c343292b5c54ddd24ce80 Mon Sep 17 00:00:00 2001 From: Mikhail Konovalov Date: Thu, 11 Jan 2018 13:00:36 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9F=D0=BE=D0=BF=D1=80=D0=B0=D0=B2=D0=B8?= =?UTF-8?q?=D0=BB=20=D1=81=D0=BE=D0=B7=D0=B4=D0=B0=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BA=D0=BE=D0=BD=D1=81=D1=82=D1=80=D0=B5=D0=B8=CC=86=D0=BD?= =?UTF-8?q?=D1=82=D0=BE=D0=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Classes/RMRPullToRefreshController.swift | 26 +++++++++++++++--------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/Classes/RMRPullToRefreshController.swift b/Classes/RMRPullToRefreshController.swift index 31aee68..8d293fa 100644 --- a/Classes/RMRPullToRefreshController.swift +++ b/Classes/RMRPullToRefreshController.swift @@ -69,23 +69,29 @@ open class RMRPullToRefreshController: NSObject { } private func addBackgroundViewConstraints(_ backgroundView: UIView) { - // Constraints - self.backgroundViewHeightConstraint = NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.height, relatedBy: NSLayoutRelation.equal, toItem: nil, attribute: NSLayoutAttribute.notAnAttribute, multiplier: 1, constant: 0) - backgroundView.addConstraint(self.backgroundViewHeightConstraint!) + guard let scrollView = scrollView, let position = position else { + return + } + + let backgroundViewHeightConstraint = backgroundView.heightAnchor.constraint(equalToConstant: 0) + backgroundViewHeightConstraint.isActive = true + self.backgroundViewHeightConstraint = backgroundViewHeightConstraint - scrollView?.addConstraint(NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.width, relatedBy: NSLayoutRelation.equal, toItem: scrollView, attribute: NSLayoutAttribute.width, multiplier: 1, constant: 0)) + backgroundView.widthAnchor.constraint(equalTo: scrollView.widthAnchor).isActive = true - if position == .top { - scrollView?.addConstraint(NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: scrollView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: 0)) - } else if position == .bottom, let scrollView = self.scrollView { + switch position { + case .top: + backgroundView.bottomAnchor.constraint(equalTo: scrollView.topAnchor).isActive = true + case .bottom: let constant = max(scrollView.contentSize.height, scrollView.bounds.height) - self.backgroundViewTopConstraint = NSLayoutConstraint(item: backgroundView, attribute: NSLayoutAttribute.top, relatedBy: NSLayoutRelation.equal, toItem: scrollView, attribute: NSLayoutAttribute.top, multiplier: 1, constant: constant) - scrollView.addConstraint(self.backgroundViewTopConstraint!) + let backgroundViewTopConstraint = backgroundView.topAnchor.constraint( + equalTo: scrollView.bottomAnchor, constant: constant) + backgroundViewTopConstraint.isActive = true + self.backgroundViewTopConstraint = backgroundViewTopConstraint } } private func configureHeight() { - if let scrollView = self.scrollView { self.originalTopInset = scrollView.contentInset.top self.originalBottomInset = scrollView.contentInset.bottom