diff --git a/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 00000000..18d98100 --- /dev/null +++ b/Example.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Sources/ButtonBarView.swift b/Sources/ButtonBarView.swift index a204971e..d8690a84 100644 --- a/Sources/ButtonBarView.swift +++ b/Sources/ButtonBarView.swift @@ -76,10 +76,28 @@ open class ButtonBarView: UICollectionView { } open func move(fromIndex: Int, toIndex: Int, progressPercentage: CGFloat, pagerScroll: PagerScroll) { + selectedIndex = progressPercentage > 0.5 ? toIndex : fromIndex - let fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame let numberOfItems = dataSource!.collectionView(self, numberOfItemsInSection: 0) + var progressPercentage = progressPercentage + + + var fromFrame: CGRect + + if fromIndex < 0 || fromIndex > numberOfItems - 1 { + if fromIndex < 0 { + let cellAtts = layoutAttributesForItem(at: IndexPath(item: 0, section: 0)) + fromFrame = cellAtts!.frame.offsetBy(dx: -cellAtts!.frame.size.width, dy: 0) + progressPercentage = 1 - progressPercentage * -1 + } else { + let cellAtts = layoutAttributesForItem(at: IndexPath(item: (numberOfItems - 1), section: 0)) + fromFrame = cellAtts!.frame.offsetBy(dx: cellAtts!.frame.size.width, dy: 0) + } + } else { + fromFrame = layoutAttributesForItem(at: IndexPath(item: fromIndex, section: 0))!.frame + } + var toFrame: CGRect @@ -95,11 +113,12 @@ open class ButtonBarView: UICollectionView { toFrame = layoutAttributesForItem(at: IndexPath(item: toIndex, section: 0))!.frame } + var targetFrame = fromFrame targetFrame.size.height = selectedBar.frame.size.height targetFrame.size.width += (toFrame.size.width - fromFrame.size.width) * progressPercentage targetFrame.origin.x += (toFrame.origin.x - fromFrame.origin.x) * progressPercentage - + selectedBar.frame = CGRect(x: targetFrame.origin.x, y: selectedBar.frame.origin.y, width: targetFrame.size.width, height: selectedBar.frame.size.height) var targetContentOffset: CGFloat = 0.0 diff --git a/Sources/ButtonCell.xib b/Sources/ButtonCell.xib index 7025bc70..456a7836 100644 --- a/Sources/ButtonCell.xib +++ b/Sources/ButtonCell.xib @@ -1,17 +1,17 @@ - + - + - + diff --git a/Sources/PagerTabStripViewController.swift b/Sources/PagerTabStripViewController.swift index 9aedb7d6..ef1c3c0b 100644 --- a/Sources/PagerTabStripViewController.swift +++ b/Sources/PagerTabStripViewController.swift @@ -299,7 +299,7 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { updateContent() } - // MARK: - UIScrollViewDelegate + // MARK: - UIScrollDelegate open func scrollViewDidScroll(_ scrollView: UIScrollView) { if containerView == scrollView { @@ -350,14 +350,21 @@ open class PagerTabStripViewController: UIViewController, UIScrollViewDelegate { fromIndex = count - 1 toIndex = count } else { - if self.scrollPercentage >= 0.5 { + if self.scrollPercentage <= 0 { + toIndex = currentIndex + fromIndex = currentIndex - 1 + } + else if self.scrollPercentage >= 0.5 { fromIndex = max(toIndex - 1, 0) } else { toIndex = fromIndex + 1 } } } else if direction == .right { - if virtualPage < 0 { + if virtualPage >= count - 1 && self.scrollPercentage > 0.5 { + fromIndex = count + toIndex = count - 1 + } else if virtualPage < 0 { fromIndex = 0 toIndex = -1 } else { diff --git a/XLPagerTabStrip.xcodeproj/xcshareddata/xcschemes/XLPagerTabStrip.xcscheme b/XLPagerTabStrip.xcodeproj/xcshareddata/xcschemes/XLPagerTabStrip.xcscheme index 3c9ff698..c5d75e2e 100644 --- a/XLPagerTabStrip.xcodeproj/xcshareddata/xcschemes/XLPagerTabStrip.xcscheme +++ b/XLPagerTabStrip.xcodeproj/xcshareddata/xcschemes/XLPagerTabStrip.xcscheme @@ -1,6 +1,10 @@ >>>>>> xmartlabs/master version = "1.3">