From 14b85fe0f4a940655cca02f6f9cf5af50b0def91 Mon Sep 17 00:00:00 2001 From: kishikawa katsumi Date: Sun, 16 Jul 2017 11:31:55 +0900 Subject: [PATCH 1/2] No longer needed to emulate UIScollView for automatic scroll insets adjustment from iOS 11. --- .../Sources/SpreadsheetView+UIScrollView.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Framework/Sources/SpreadsheetView+UIScrollView.swift b/Framework/Sources/SpreadsheetView+UIScrollView.swift index 92123027..71f14503 100644 --- a/Framework/Sources/SpreadsheetView+UIScrollView.swift +++ b/Framework/Sources/SpreadsheetView+UIScrollView.swift @@ -10,7 +10,11 @@ import UIKit extension SpreadsheetView { public override func isKind(of aClass: AnyClass) -> Bool { - return rootView.isKind(of: aClass) + if #available(iOS 11.0, *) { + return super.isKind(of: aClass) + } else { + return rootView.isKind(of: aClass) + } } public var contentOffset: CGPoint { @@ -52,10 +56,14 @@ extension SpreadsheetView { } public override func forwardingTarget(for aSelector: Selector!) -> Any? { - if overlayView.responds(to: aSelector) { - return overlayView - } else { + if #available(iOS 11.0, *) { return super.forwardingTarget(for: aSelector) + } else { + if overlayView.responds(to: aSelector) { + return overlayView + } else { + return super.forwardingTarget(for: aSelector) + } } } } From ebf3edf5e289a587d478ee0a1eaa49f6c2d32f62 Mon Sep 17 00:00:00 2001 From: kishikawa katsumi Date: Sun, 16 Jul 2017 23:30:17 +0900 Subject: [PATCH 2/2] Support new automatic content inset adjustment on iOS 11 --- .../Sources/SpreadsheetView+Layout.swift | 44 ++++++++++++++----- ...SpreadsheetView+UIScrollViewDelegate.swift | 6 +++ Framework/Sources/SpreadsheetView.swift | 1 + 3 files changed, 39 insertions(+), 12 deletions(-) diff --git a/Framework/Sources/SpreadsheetView+Layout.swift b/Framework/Sources/SpreadsheetView+Layout.swift index 3609e0e9..1469372f 100644 --- a/Framework/Sources/SpreadsheetView+Layout.swift +++ b/Framework/Sources/SpreadsheetView+Layout.swift @@ -275,31 +275,37 @@ extension SpreadsheetView { } func adjustScrollViewFrames() { + let contentInset: UIEdgeInsets + if #available(iOS 11.0, *) { + contentInset = rootView.value(forKey: "adjustedContentInset") as! UIEdgeInsets + } else { + contentInset = rootView.contentInset + } if frozenColumns > 0 { if circularScrollingOptions.headerStyle != .columnHeaderStartsFirstRow { columnHeaderView.frame.origin.y = frozenRows > 0 ? rowHeaderView.frame.height : 0 } - let height = rootView.frame.height - (rootView.contentInset.top + rootView.contentInset.bottom) - (circularScrollingOptions.headerStyle == .columnHeaderStartsFirstRow ? 0 : rowHeaderView.frame.height) + let height = rootView.frame.height - (contentInset.top + contentInset.bottom) - (circularScrollingOptions.headerStyle == .columnHeaderStartsFirstRow ? 0 : rowHeaderView.frame.height) columnHeaderView.frame.size.height = height < 0 ? 0 : height tableView.frame.origin.x = columnHeaderView.frame.width - intercellSpacing.width - tableView.frame.size.width = (rootView.frame.width - (rootView.contentInset.left + rootView.contentInset.right)) - (columnHeaderView.frame.width - intercellSpacing.width) + tableView.frame.size.width = (rootView.frame.width - (contentInset.left + contentInset.right)) - (columnHeaderView.frame.width - intercellSpacing.width) } else { - tableView.frame.size.width = (rootView.frame.width - (rootView.contentInset.left + rootView.contentInset.right)) + tableView.frame.size.width = (rootView.frame.width - (contentInset.left + contentInset.right)) } if frozenRows > 0 { if circularScrollingOptions.headerStyle != .rowHeaderStartsFirstColumn { rowHeaderView.frame.origin.x = frozenColumns > 0 ? columnHeaderView.frame.width : 0 } - let width = rootView.frame.width - (rootView.contentInset.left + rootView.contentInset.right) - (circularScrollingOptions.headerStyle == .rowHeaderStartsFirstColumn ? 0 : columnHeaderView.frame.width) + let width = rootView.frame.width - (contentInset.left + contentInset.right) - (circularScrollingOptions.headerStyle == .rowHeaderStartsFirstColumn ? 0 : columnHeaderView.frame.width) rowHeaderView.frame.size.width = width < 0 ? 0 : width tableView.frame.origin.y = rowHeaderView.frame.height - intercellSpacing.height - tableView.frame.size.height = (rootView.frame.height - (rootView.contentInset.top + rootView.contentInset.bottom)) - (rowHeaderView.frame.height - intercellSpacing.height) + tableView.frame.size.height = (rootView.frame.height - (contentInset.top + contentInset.bottom)) - (rowHeaderView.frame.height - intercellSpacing.height) } else { - tableView.frame.size.height = (rootView.frame.height - (rootView.contentInset.top + rootView.contentInset.bottom)) + tableView.frame.size.height = (rootView.frame.height - (contentInset.top + contentInset.bottom)) } if frozenColumns > 0 && frozenRows > 0 { if circularScrollingOptions.headerStyle != .columnHeaderStartsFirstRow { @@ -314,8 +320,15 @@ extension SpreadsheetView { } func adjustScrollViewSizes() { - let width = rootView.frame.width - rootView.contentInset.left - rootView.contentInset.right - + (frozenColumns > 0 ? -columnHeaderView.frame.width + intercellSpacing.width : 0) + let contentInset: UIEdgeInsets + if #available(iOS 11.0, *) { + contentInset = rootView.value(forKey: "adjustedContentInset") as! UIEdgeInsets + } else { + contentInset = rootView.contentInset + } + + let width = rootView.frame.width - contentInset.left - contentInset.right + + (frozenColumns > 0 ? -columnHeaderView.frame.width + intercellSpacing.width : 0) if width > 0 { if width != tableView.frame.size.width { rowHeaderView.frame.size.width = width @@ -326,8 +339,8 @@ extension SpreadsheetView { tableView.frame.size.width = 0 } - let height = rootView.frame.height - rootView.contentInset.top - rootView.contentInset.bottom - + (frozenRows > 0 ? -rowHeaderView.frame.height + intercellSpacing.height : 0) + let height = rootView.frame.height - contentInset.top - contentInset.bottom + + (frozenRows > 0 ? -rowHeaderView.frame.height + intercellSpacing.height : 0) if height > 0 { if height != tableView.frame.size.height { columnHeaderView.frame.size.height = height @@ -340,8 +353,15 @@ extension SpreadsheetView { } func adjustOverlayViewContentSize() { - overlayView.contentSize = CGSize(width: rootView.contentInset.left + rootView.contentInset.right + tableView.frame.origin.x - intercellSpacing.width + tableView.contentSize.width, - height: rootView.contentInset.top + rootView.contentInset.bottom + tableView.frame.origin.y - intercellSpacing.height + tableView.contentSize.height) + let contentInset: UIEdgeInsets + if #available(iOS 11.0, *) { + contentInset = rootView.value(forKey: "adjustedContentInset") as! UIEdgeInsets + } else { + contentInset = rootView.contentInset + } + let width = contentInset.left + contentInset.right + tableView.frame.origin.x - intercellSpacing.width + tableView.contentSize.width + let height = contentInset.top + contentInset.bottom + tableView.frame.origin.y - intercellSpacing.height + tableView.contentSize.height + overlayView.contentSize = CGSize(width: width, height: height) } func arrangeScrollViews() { diff --git a/Framework/Sources/SpreadsheetView+UIScrollViewDelegate.swift b/Framework/Sources/SpreadsheetView+UIScrollViewDelegate.swift index 3366c007..4b4228c8 100644 --- a/Framework/Sources/SpreadsheetView+UIScrollViewDelegate.swift +++ b/Framework/Sources/SpreadsheetView+UIScrollViewDelegate.swift @@ -52,4 +52,10 @@ extension SpreadsheetView: UIScrollViewDelegate { delegate?.spreadsheetView(self, didSelectItemAt: indexPath) pendingSelectionIndexPath = nil } + + @available(iOS 11.0, *) + public func scrollViewDidChangeAdjustedContentInset(_ scrollView: UIScrollView) { + adjustScrollViewSizes() + adjustOverlayViewContentSize() + } } diff --git a/Framework/Sources/SpreadsheetView.swift b/Framework/Sources/SpreadsheetView.swift index aa2278a8..9a9b41a3 100644 --- a/Framework/Sources/SpreadsheetView.swift +++ b/Framework/Sources/SpreadsheetView.swift @@ -325,6 +325,7 @@ public class SpreadsheetView: UIView { rootView.autoresizingMask = [.flexibleWidth, .flexibleHeight] rootView.showsHorizontalScrollIndicator = false rootView.showsVerticalScrollIndicator = false + rootView.delegate = self super.addSubview(rootView) tableView.frame = bounds