77
88import UIKit
99
10- public protocol StickyHeaderTabControllerDelegate : class {
11- func stickyHeaderTabControllerDidScrollVertically( _ controller: StickyHeaderTabController )
10+ @objc public protocol StickyHeaderTabControllerDelegate : class {
11+ @objc optional func stickyHeaderTabController( _ controller: StickyHeaderTabController ,
12+ didUpdateCompoundHeaderHeight headerHeight: CGFloat )
13+ @objc optional func stickyHeaderTabControllerDidScrollVertically( _ controller: StickyHeaderTabController )
1214}
1315
1416open class StickyHeaderTabController : UIViewController {
@@ -71,6 +73,7 @@ open class StickyHeaderTabController: UIViewController {
7173 /// Could instead be a calculated variable, but then we lose the `didSet` functionality.
7274 fileprivate var compoundHeaderHeight : CGFloat = 0.0 {
7375 didSet {
76+ delegate? . stickyHeaderTabController ? ( self , didUpdateCompoundHeaderHeight: compoundHeaderHeight)
7477 updateInsetForCompoundHeaderHeight ( compoundHeaderHeight)
7578 }
7679 }
@@ -86,7 +89,7 @@ open class StickyHeaderTabController: UIViewController {
8689 /// gesture began.
8790 fileprivate weak var activeVerticalTab : StickyHeaderContentTabViewController ?
8891
89- private let verticalPanRecognizer = UIPanGestureRecognizer ( )
92+ fileprivate let verticalPanRecognizer = UIPanGestureRecognizer ( )
9093
9194 // MARK: AutoLayout magic
9295
@@ -149,8 +152,6 @@ open class StickyHeaderTabController: UIViewController {
149152
150153 horizontalScrollView. frame = view. bounds
151154 horizontalScrollView. autoresizingMask = [ . flexibleWidth, . flexibleHeight]
152-
153- // view.insertSubview(gradientBackground, at: 0)
154155 }
155156
156157 private func setUpVerticalPanRecognizer( ) {
@@ -337,14 +338,19 @@ open class StickyHeaderTabController: UIViewController {
337338 stickyGuideTopConstraint? . constant = - trueScrollOffset
338339
339340 let offsetY = trueScrollOffset - compoundHeaderHeight
340- for tab in tabs {
341- if tab != activeVerticalTab {
342- // TODO: Refine this to account for differences in `contentSize`
343- tab. contentOffset = CGPoint ( x: 0 , y: offsetY)
341+ let isTabBarPinned = tabBar. frame. origin. y <= stickyHeader. pinnedHeight
342+ let otherTabs = tabs. filter { tab -> Bool in tab != activeVerticalTab }
343+ for otherTab in otherTabs {
344+ var newOffsetY = offsetY
345+ if isTabBarPinned {
346+ let tabBottom = tabBar. frame. origin. y + tabBar. frame. height
347+ newOffsetY = max ( otherTab. contentOffset. y, - tabBottom)
344348 }
349+
350+ otherTab. contentOffset = CGPoint ( x: 0 , y: newOffsetY)
345351 }
346352
347- delegate? . stickyHeaderTabControllerDidScrollVertically ( self )
353+ delegate? . stickyHeaderTabControllerDidScrollVertically ? ( self )
348354 }
349355
350356 fileprivate func scrollToTabIndex( _ tabIndex: Int , animated: Bool = true ) {
@@ -423,6 +429,7 @@ open class StickyHeaderTabController: UIViewController {
423429extension StickyHeaderTabController : StickyHeaderTabBarViewDelegate {
424430 public func stickyHeaderTabBarView( _ stickyHeaderTabBarView: StickyHeaderTabBarView ,
425431 tabSelectedAtIndex index: Int ) {
432+ verticalPanRecognizer. cancelCurrentGesture ( )
426433 scrollToTabIndex ( index, animated: true )
427434 }
428435}
@@ -438,15 +445,6 @@ extension StickyHeaderTabController: StickyHeaderTabBarViewDataSource {
438445 }
439446}
440447
441- // MARK: - StickyHeaderViewDelegate
442-
443- extension StickyHeaderTabController : StickyHeaderViewDelegate {
444- public func stickyHeaderView( _ stickyHeaderView: StickyHeaderView ,
445- didChangeHeight height: CGFloat ) {
446- updateCompoundHeaderHeight ( )
447- }
448- }
449-
450448// MARK: - UIScrollViewDelegate
451449
452450extension StickyHeaderTabController : UIScrollViewDelegate {
@@ -480,6 +478,6 @@ extension StickyHeaderTabController: UIScrollViewDelegate {
480478extension StickyHeaderTabController : UIGestureRecognizerDelegate {
481479 public func gestureRecognizer( _ gestureRecognizer: UIGestureRecognizer ,
482480 shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer ) -> Bool {
483- return false // true
481+ return true
484482 }
485483}
0 commit comments