From 03adee6f8dca4c4aa720e8dd47dc733b02dc3459 Mon Sep 17 00:00:00 2001 From: Jacob Schwartz Date: Fri, 13 Sep 2019 18:34:40 -0700 Subject: [PATCH 1/2] do not scroll above safe area of content --- Sources/PagerTabStripViewController.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/Sources/PagerTabStripViewController.swift b/Sources/PagerTabStripViewController.swift index 9aedb7d6..3e295a94 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/PagerTabStripViewController.swift @@ -154,6 +154,13 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { return } + let top: CGFloat + if #available(iOS 11.0, *) { + top = -containerView.adjustedContentInset.top + } else { + top = 0 + } + if animated && pagerBehaviour.skipIntermediateViewControllers && abs(currentIndex - index) > 1 { var tmpViewControllers = viewControllers let currentChildVC = viewControllers[currentIndex] @@ -162,12 +169,12 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { tmpViewControllers[currentIndex] = fromChildVC tmpViewControllers[fromIndex] = currentChildVC pagerTabStripChildViewControllersForScrolling = tmpViewControllers - containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: fromIndex), y: 0), animated: false) + containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: fromIndex), y: top), animated: false) (navigationController?.view ?? view).isUserInteractionEnabled = !animated - containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: index), y: 0), animated: true) + containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: index), y: top), animated: true) } else { (navigationController?.view ?? view).isUserInteractionEnabled = !animated - containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: index), y: 0), animated: animated) + containerView.setContentOffset(CGPoint(x: pageOffsetForChild(at: index), y: top), animated: animated) } } From b62e55bb149570bcbc47e43faaf37b8b5014631e Mon Sep 17 00:00:00 2001 From: Jacob Schwartz Date: Fri, 13 Sep 2019 18:43:14 -0700 Subject: [PATCH 2/2] pre iOS 11 support --- Sources/PagerTabStripViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/PagerTabStripViewController.swift b/Sources/PagerTabStripViewController.swift index 3e295a94..269a849c 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/PagerTabStripViewController.swift @@ -158,7 +158,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { if #available(iOS 11.0, *) { top = -containerView.adjustedContentInset.top } else { - top = 0 + top = -containerView.contentInset.top } if animated && pagerBehaviour.skipIntermediateViewControllers && abs(currentIndex - index) > 1 {