diff --git a/Example/Podfile.lock b/Example/Podfile.lock index ee3a04ba..7f3bcfda 100644 --- a/Example/Podfile.lock +++ b/Example/Podfile.lock @@ -6,11 +6,11 @@ DEPENDENCIES: EXTERNAL SOURCES: PagingMenuController: - :path: "../" + :path: ../ SPEC CHECKSUMS: PagingMenuController: 60602bfb5421d6536c1e3097baeed601dec1d85b PODFILE CHECKSUM: ad8a39de8cc58c1b803b2e2b316ca0de8adca12c -COCOAPODS: 1.1.0.rc.2 +COCOAPODS: 1.1.1 diff --git a/Pod/Classes/MenuView.swift b/Pod/Classes/MenuView.swift index 7461ae72..dd9ec9b2 100644 --- a/Pod/Classes/MenuView.swift +++ b/Pod/Classes/MenuView.swift @@ -8,6 +8,8 @@ import UIKit +internal let MenuViewItemsMarginRigth: CGFloat = 20 + open class MenuView: UIScrollView { public fileprivate(set) var currentMenuItemView: MenuItemView! @@ -65,9 +67,19 @@ open class MenuView: UIScrollView { return menuItemViews[currentPage].frame.midX - screenWidth / 2 } fileprivate var contentOffsetXForCurrentPage: CGFloat { - guard menuItemCount > MinimumSupportedViewCount else { return 0.0 } - let ratio = CGFloat(currentPage) / CGFloat(menuItemCount - 1) - return (contentSize.width - frame.width) * ratio + // Get the content offset X for the current element so the next one will be visible. + let currentElementFrame = menuItemViews[currentPage].frame + let deviceWidth = (UIApplication.shared.keyWindow!.bounds.width) + + if (currentPage == menuItemViews.count - 1) { + // Current element is the last element. + let leadingValue = deviceWidth - (currentElementFrame.size.width + MenuViewItemsMarginRigth) + return max(currentElementFrame.origin.x - leadingValue, 0) + } + // There is a nextElement we should care about. + let nextElement = menuItemViews[currentPage + 1] + let leadingValue = deviceWidth - (currentElementFrame.size.width + nextElement.frame.size.width / 2 + MenuViewItemsMarginRigth) + return max(currentElementFrame.origin.x - leadingValue, 0) } fileprivate var currentIndex: Int = 0