From b6c85e05bfafc93feedaa44b14f35556c8556699 Mon Sep 17 00:00:00 2001 From: Luc Dion Date: Wed, 28 Mar 2018 19:32:54 -0400 Subject: [PATCH] Add iPad multitask support to the example app. --- .../CollectionViewExampleView.swift | 18 ++++++------------ .../CollectionViewExampleViewController.swift | 5 +++++ .../CollectionViewExample/HouseCell.swift | 6 +++--- .../TableViewExample/Cells/MethodCell.swift | 2 +- .../Cells/MethodGroupHeader.swift | 2 +- .../TableViewExampleView.swift | 7 +++---- Podfile.lock | 4 ++-- 7 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift b/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift index 6796fb9f..accfcd65 100644 --- a/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift +++ b/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift @@ -50,10 +50,14 @@ class CollectionViewExampleView: UIView { self.houses = houses collectionView.reloadData() } + + func viewOrientationDidChange() { + flowLayout.invalidateLayout() + } override func layoutSubviews() { super.layoutSubviews() - collectionView.pin.all() + collectionView.pin.all(pin.safeArea) } } @@ -70,17 +74,7 @@ extension CollectionViewExampleView: UICollectionViewDelegateFlowLayout, UIColle } func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { - let adjustedWidth = adjustWidthWithSafeArea(collectionView.bounds.width) - cellTemplate.configure(house: houses[indexPath.row]) - return cellTemplate.sizeThatFits(CGSize(width: adjustedWidth, height: .greatestFiniteMagnitude)) - } - - private func adjustWidthWithSafeArea(_ width: CGFloat) -> CGFloat { - if #available(iOS 11.0, tvOS 11.0, *) { - return width - safeAreaInsets.left - safeAreaInsets.right - } else { - return width - } + return cellTemplate.sizeThatFits(CGSize(width: collectionView.bounds.width, height: .greatestFiniteMagnitude)) } } diff --git a/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleViewController.swift b/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleViewController.swift index 43e568da..ad17237b 100644 --- a/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleViewController.swift +++ b/Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleViewController.swift @@ -61,4 +61,9 @@ class CollectionViewExampleViewController: UIViewController { mainImageURL: URL(string: "https://i.pinimg.com/736x/6d/6c/ab/6d6cab9db70117727e3eb2adf0dbc080--small-modern-house-plans-modern-houses.jpg")!) ]) } + + override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) { + super.viewWillTransition(to: size, with: coordinator) + mainView.viewOrientationDidChange() + } } diff --git a/Example/PinLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift b/Example/PinLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift index df6bb943..6b7761da 100644 --- a/Example/PinLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift +++ b/Example/PinLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift @@ -79,12 +79,12 @@ class HouseCell: UICollectionViewCell { } private func layout() { - headerView.pin.top().horizontally().height(100) + headerView.pin.top().horizontally(pin.safeArea).height(100) nameLabel.pin.top().horizontally().margin(padding).sizeToFit(.width) - mainImage.pin.below(of: nameLabel).horizontally().height(300).marginTop(padding) + mainImage.pin.below(of: nameLabel).horizontally(pin.safeArea).height(300).marginTop(padding) - footerView.pin.below(of: mainImage).horizontally() + footerView.pin.below(of: mainImage).horizontally(pin.safeArea) priceLabel.pin.top().horizontally().margin(6, padding).sizeToFit(.width) distanceLabel.pin.top().after(of: priceLabel).right().margin(6, padding).sizeToFit(.width) footerView.pin.height(max(priceLabel.frame.maxY, distanceLabel.frame.maxY) + 6) diff --git a/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift b/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift index e7fb8799..0ec1757c 100644 --- a/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift +++ b/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift @@ -62,7 +62,7 @@ class MethodCell: UITableViewCell { fileprivate func layout() { iconImageView.pin.top().left().size(30).margin(padding) nameLabel.pin.right(of: iconImageView, aligned: .center).right().marginHorizontal(padding).sizeToFit(.width) - descriptionLabel.pin.below(of: [iconImageView, nameLabel]).left().right().margin(padding).sizeToFit(.width) + descriptionLabel.pin.below(of: [iconImageView, nameLabel]).horizontally().margin(padding).sizeToFit(.width) } override func sizeThatFits(_ size: CGSize) -> CGSize { diff --git a/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodGroupHeader.swift b/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodGroupHeader.swift index 9bbdd331..5dd3d036 100644 --- a/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodGroupHeader.swift +++ b/Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodGroupHeader.swift @@ -43,6 +43,6 @@ class MethodGroupHeader: UITableViewHeaderFooterView { override func layoutSubviews() { super.layoutSubviews() - titleLabel.pin.left().right().vCenter().margin(10).sizeToFit(.width) + titleLabel.pin.horizontally().vCenter().margin(10).sizeToFit(.width) } } diff --git a/Example/PinLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift b/Example/PinLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift index b0124ccd..8cc8f450 100644 --- a/Example/PinLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift +++ b/Example/PinLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift @@ -30,7 +30,6 @@ class TableViewExampleView: UIView { super.init(frame: .zero) backgroundColor = .white - tableView.estimatedRowHeight = 10 tableView.dataSource = self tableView.delegate = self tableView.tableFooterView = UIView() @@ -79,8 +78,8 @@ extension TableViewExampleView: UITableViewDataSource, UITableViewDelegate { } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { - // The UITableView will call the cell's sizeThatFit() method to compute the height. - // WANRING: You must also set the UITableView.estimatedRowHeight for this to work. - return UITableViewAutomaticDimension + // Configure a MethodCell and ask its size. + methodCellTemplate.configure(method: methods[indexPath.row]) + return methodCellTemplate.sizeThatFits(CGSize(width: tableView.bounds.width, height: .greatestFiniteMagnitude)).height } } diff --git a/Podfile.lock b/Podfile.lock index 5933b944..5da2131b 100644 --- a/Podfile.lock +++ b/Podfile.lock @@ -1,6 +1,6 @@ PODS: - Nimble (7.0.3) - - PinLayout (1.5.9) + - PinLayout (1.6.0) - Quick (1.2.0) - Reveal-SDK (10) - SwiftLint (0.25.0) @@ -18,7 +18,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac - PinLayout: b2ebf8622b28e82b6e1216ab4e4a0a8d082214fe + PinLayout: a2bbe9057d49a1e326b13dc4fe8c14751f8c8844 Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08 Reveal-SDK: 7869ddf1f902cabbb07a1f0dd06bd25861a126f7 SwiftLint: e14651157288e9e01d6e1a71db7014fb5744a8ea