From bf8edc820b4668f2751192d1070d8dc4503eff68 Mon Sep 17 00:00:00 2001 From: Martin Barreto Date: Thu, 26 Jan 2017 16:50:20 -0300 Subject: [PATCH] =?UTF-8?q?=E2=80=9CTwitterPagerTabStripViewController=20c?= =?UTF-8?q?rash=20on=20back=20navigation=E2=80=9D=20fixed.=20#178?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Sources/TwitterPagerTabStripViewController.swift | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Sources/TwitterPagerTabStripViewController.swift b/Sources/TwitterPagerTabStripViewController.swift index e8093b4..513268b 100644 --- a/Sources/TwitterPagerTabStripViewController.swift +++ b/Sources/TwitterPagerTabStripViewController.swift @@ -87,7 +87,7 @@ open class TwitterPagerTabStripViewController: PagerTabStripViewController, Page open func updateIndicator(for viewController: PagerTabStripViewController, fromIndex: Int, toIndex: Int, withProgressPercentage progressPercentage: CGFloat, indexWasChanged: Bool) { // move indicator scroll view - let distance = distanceValue + guard let distance = distanceValue else { return } var xOffset: CGFloat = 0 if fromIndex < toIndex { xOffset = distance * CGFloat(fromIndex) + distance * progressPercentage @@ -193,7 +193,7 @@ open class TwitterPagerTabStripViewController: PagerTabStripViewController, Page } private func setNavigationViewItemsPosition(updateAlpha: Bool) { - let distance = distanceValue + guard let distance = distanceValue else { return } let isPortrait = UIApplication.shared.statusBarOrientation.isPortrait let navBarHeight: CGFloat = navigationController!.navigationBar.frame.size.height for (index, label) in childTitleLabels.enumerated() { @@ -231,8 +231,7 @@ open class TwitterPagerTabStripViewController: PagerTabStripViewController, Page } } - private var distanceValue: CGFloat { - let middle = navigationController!.navigationBar.convert(navigationController!.navigationBar.center, to: titleView) - return middle.x + private var distanceValue: CGFloat? { + return navigationController.map { $0.navigationBar.convert($0.navigationBar.center, to: titleView) }?.x } }