From 1deabeaafb99c8adaca05f6ea5a67a48d8e9d0c6 Mon Sep 17 00:00:00 2001 From: Leo Mehlig Date: Thu, 6 Jul 2017 17:52:44 +0200 Subject: [PATCH] Adds stickyRow/Column-Header options If set to `true` the header always stays at the top. Even if the user bounces. --- Framework/Sources/SpreadsheetView+Layout.swift | 11 +++++++++++ Framework/Sources/SpreadsheetView.swift | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/Framework/Sources/SpreadsheetView+Layout.swift b/Framework/Sources/SpreadsheetView+Layout.swift index 96c83c8c..d4daeceb 100644 --- a/Framework/Sources/SpreadsheetView+Layout.swift +++ b/Framework/Sources/SpreadsheetView+Layout.swift @@ -35,6 +35,17 @@ extension SpreadsheetView { layoutRowHeader() layoutColumnHeader() + if self.stickyRowHeader { + self.rowHeaderView.frame.origin.y = min(self.rootView.contentOffset.y, 0) + self.rowHeaderView.contentOffset.x = self.tableView.contentOffset.x + self.cornerView.frame.origin.y = min(self.rootView.contentOffset.y, 0) + } + if self.stickyColumnHeader { + self.columnHeaderView.frame.origin.x = min(self.rootView.contentOffset.x, 0) + self.columnHeaderView.contentOffset.y = self.tableView.contentOffset.y + self.cornerView.frame.origin.x = min(self.rootView.contentOffset.x, 0) + } + if needsReload { adjustScrollViewFrames() diff --git a/Framework/Sources/SpreadsheetView.swift b/Framework/Sources/SpreadsheetView.swift index aa2278a8..9dcba55b 100644 --- a/Framework/Sources/SpreadsheetView.swift +++ b/Framework/Sources/SpreadsheetView.swift @@ -219,6 +219,20 @@ public class SpreadsheetView: UIView { tableView.alwaysBounceHorizontal = newValue } } + + /// A Boolean value that determines wheather the row header always sticks to the top. + /// - Note: `bounces` has to be `true` and there has to be at least one `frozenRow`. + /// The default value is `false`. + /// + /// - SeeAlso: `stickyColumnHeader` + public var stickyRowHeader: Bool = false + + /// A Boolean value that determines wheather the column header always sticks to the top. + /// - Note: `bounces` has to be `true` and there has to be at least one `frozenColumn`. + /// The default value is `false`. + /// + /// - SeeAlso: `stickyRowHeader` + public var stickyColumnHeader: Bool = false /// A Boolean value that determines whether paging is enabled for the scroll view. /// - Note: If the value of this property is `true`, the scroll view stops on multiples of the scroll view’s bounds when the user scrolls.