Skip to content

Commit

Permalink
Merge pull request #90 from kishikawakatsumi/ios11
Browse files Browse the repository at this point in the history
Fix an issue that an app crashes if spreadsheet view with UINavigationController on iOS 11
  • Loading branch information
kishikawakatsumi authored Jul 16, 2017
2 parents 5c976a5 + ebf3edf commit 2551513
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 16 deletions.
44 changes: 32 additions & 12 deletions Framework/Sources/SpreadsheetView+Layout.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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() {
Expand Down
16 changes: 12 additions & 4 deletions Framework/Sources/SpreadsheetView+UIScrollView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
}
}
}
6 changes: 6 additions & 0 deletions Framework/Sources/SpreadsheetView+UIScrollViewDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}
1 change: 1 addition & 0 deletions Framework/Sources/SpreadsheetView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 2551513

Please sign in to comment.