-
-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable to restrict the content size in FloatingPanelAdaptiveLayoutAnc…
…hor (#518) * Introduce FloatingPanelLayoutContentBoundingGuide property for FloatingPanelAdaptiveLayoutAnchor * Revise doc comments * Clean up code * Update the minimum deployment target of Samples app to iOS 11
- Loading branch information
Showing
12 changed files
with
335 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
Examples/Samples/Sources/ContentViewControllers/AdaptiveLayoutTestViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
// Copyright 2018-Present Shin Yamamoto. All rights reserved. MIT license. | ||
|
||
import UIKit | ||
import FloatingPanel | ||
|
||
final class AdaptiveLayoutTestViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { | ||
class PanelLayout: FloatingPanelLayout { | ||
let position: FloatingPanelPosition = .bottom | ||
let initialState: FloatingPanelState = .full | ||
|
||
private unowned var targetGuide: UILayoutGuide | ||
|
||
init(targetGuide: UILayoutGuide) { | ||
self.targetGuide = targetGuide | ||
} | ||
|
||
var anchors: [FloatingPanelState : FloatingPanelLayoutAnchoring] { | ||
return [ | ||
.full: FloatingPanelAdaptiveLayoutAnchor( | ||
absoluteOffset: 0.0, | ||
contentLayout: targetGuide, | ||
referenceGuide: .superview, | ||
contentBoundingGuide: .safeArea | ||
), | ||
.half: FloatingPanelAdaptiveLayoutAnchor( | ||
fractionalOffset: 0.5, | ||
contentLayout: targetGuide, | ||
referenceGuide: .superview, | ||
contentBoundingGuide: .safeArea | ||
), | ||
] | ||
} | ||
} | ||
|
||
@IBOutlet weak var tableView: IntrinsicTableView! | ||
private let cellID = "Cell" | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
tableView.rowHeight = UITableView.automaticDimension | ||
tableView.register(UITableViewCell.self, forCellReuseIdentifier: cellID) | ||
} | ||
|
||
// MARK: - UITableViewDataSource | ||
|
||
func numberOfSections(in tableView: UITableView) -> Int { | ||
1 | ||
} | ||
|
||
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { | ||
50 | ||
} | ||
|
||
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { | ||
let cell = tableView.dequeueReusableCell(withIdentifier: cellID, for: indexPath) | ||
cell.textLabel?.text = "\(indexPath.row)" | ||
return cell | ||
} | ||
|
||
// MARK: - UITableViewDelegate | ||
|
||
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { | ||
let headerView = UIView() | ||
headerView.backgroundColor = .orange | ||
return headerView | ||
} | ||
|
||
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { | ||
44.0 | ||
} | ||
|
||
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { | ||
40 | ||
} | ||
} | ||
|
||
class IntrinsicTableView: UITableView { | ||
|
||
override var contentSize:CGSize { | ||
didSet { | ||
invalidateIntrinsicContentSize() | ||
} | ||
} | ||
|
||
override var intrinsicContentSize: CGSize { | ||
layoutIfNeeded() | ||
return CGSize(width: UIView.noIntrinsicMetric, height: contentSize.height) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.