Skip to content

Commit 4d1c757

Browse files
authored
Merge pull request #129 from mirego/Update_example_app_to_support_ipad_multitask
Add iPad multitask support to the example app.
2 parents 8911cb9 + b6c85e0 commit 4d1c757

File tree

7 files changed

+21
-23
lines changed

7 files changed

+21
-23
lines changed

Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleView.swift

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ class CollectionViewExampleView: UIView {
5050
self.houses = houses
5151
collectionView.reloadData()
5252
}
53+
54+
func viewOrientationDidChange() {
55+
flowLayout.invalidateLayout()
56+
}
5357

5458
override func layoutSubviews() {
5559
super.layoutSubviews()
56-
collectionView.pin.all()
60+
collectionView.pin.all(pin.safeArea)
5761
}
5862
}
5963

@@ -70,17 +74,7 @@ extension CollectionViewExampleView: UICollectionViewDelegateFlowLayout, UIColle
7074
}
7175

7276
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
73-
let adjustedWidth = adjustWidthWithSafeArea(collectionView.bounds.width)
74-
7577
cellTemplate.configure(house: houses[indexPath.row])
76-
return cellTemplate.sizeThatFits(CGSize(width: adjustedWidth, height: .greatestFiniteMagnitude))
77-
}
78-
79-
private func adjustWidthWithSafeArea(_ width: CGFloat) -> CGFloat {
80-
if #available(iOS 11.0, tvOS 11.0, *) {
81-
return width - safeAreaInsets.left - safeAreaInsets.right
82-
} else {
83-
return width
84-
}
78+
return cellTemplate.sizeThatFits(CGSize(width: collectionView.bounds.width, height: .greatestFiniteMagnitude))
8579
}
8680
}

Example/PinLayoutSample/UI/Examples/CollectionViewExample/CollectionViewExampleViewController.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,9 @@ class CollectionViewExampleViewController: UIViewController {
6161
mainImageURL: URL(string: "https://i.pinimg.com/736x/6d/6c/ab/6d6cab9db70117727e3eb2adf0dbc080--small-modern-house-plans-modern-houses.jpg")!)
6262
])
6363
}
64+
65+
override func viewWillTransition(to size: CGSize, with coordinator: UIViewControllerTransitionCoordinator) {
66+
super.viewWillTransition(to: size, with: coordinator)
67+
mainView.viewOrientationDidChange()
68+
}
6469
}

Example/PinLayoutSample/UI/Examples/CollectionViewExample/HouseCell.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ class HouseCell: UICollectionViewCell {
7979
}
8080

8181
private func layout() {
82-
headerView.pin.top().horizontally().height(100)
82+
headerView.pin.top().horizontally(pin.safeArea).height(100)
8383
nameLabel.pin.top().horizontally().margin(padding).sizeToFit(.width)
8484

85-
mainImage.pin.below(of: nameLabel).horizontally().height(300).marginTop(padding)
85+
mainImage.pin.below(of: nameLabel).horizontally(pin.safeArea).height(300).marginTop(padding)
8686

87-
footerView.pin.below(of: mainImage).horizontally()
87+
footerView.pin.below(of: mainImage).horizontally(pin.safeArea)
8888
priceLabel.pin.top().horizontally().margin(6, padding).sizeToFit(.width)
8989
distanceLabel.pin.top().after(of: priceLabel).right().margin(6, padding).sizeToFit(.width)
9090
footerView.pin.height(max(priceLabel.frame.maxY, distanceLabel.frame.maxY) + 6)

Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodCell.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ class MethodCell: UITableViewCell {
6262
fileprivate func layout() {
6363
iconImageView.pin.top().left().size(30).margin(padding)
6464
nameLabel.pin.right(of: iconImageView, aligned: .center).right().marginHorizontal(padding).sizeToFit(.width)
65-
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).left().right().margin(padding).sizeToFit(.width)
65+
descriptionLabel.pin.below(of: [iconImageView, nameLabel]).horizontally().margin(padding).sizeToFit(.width)
6666
}
6767

6868
override func sizeThatFits(_ size: CGSize) -> CGSize {

Example/PinLayoutSample/UI/Examples/TableViewExample/Cells/MethodGroupHeader.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@ class MethodGroupHeader: UITableViewHeaderFooterView {
4343
override func layoutSubviews() {
4444
super.layoutSubviews()
4545

46-
titleLabel.pin.left().right().vCenter().margin(10).sizeToFit(.width)
46+
titleLabel.pin.horizontally().vCenter().margin(10).sizeToFit(.width)
4747
}
4848
}

Example/PinLayoutSample/UI/Examples/TableViewExample/TableViewExampleView.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ class TableViewExampleView: UIView {
3030
super.init(frame: .zero)
3131
backgroundColor = .white
3232

33-
tableView.estimatedRowHeight = 10
3433
tableView.dataSource = self
3534
tableView.delegate = self
3635
tableView.tableFooterView = UIView()
@@ -79,8 +78,8 @@ extension TableViewExampleView: UITableViewDataSource, UITableViewDelegate {
7978
}
8079

8180
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
82-
// The UITableView will call the cell's sizeThatFit() method to compute the height.
83-
// WANRING: You must also set the UITableView.estimatedRowHeight for this to work.
84-
return UITableViewAutomaticDimension
81+
// Configure a MethodCell and ask its size.
82+
methodCellTemplate.configure(method: methods[indexPath.row])
83+
return methodCellTemplate.sizeThatFits(CGSize(width: tableView.bounds.width, height: .greatestFiniteMagnitude)).height
8584
}
8685
}

Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
PODS:
22
- Nimble (7.0.3)
3-
- PinLayout (1.5.9)
3+
- PinLayout (1.6.0)
44
- Quick (1.2.0)
55
- Reveal-SDK (10)
66
- SwiftLint (0.25.0)
@@ -18,7 +18,7 @@ EXTERNAL SOURCES:
1818

1919
SPEC CHECKSUMS:
2020
Nimble: 7f5a9c447a33002645a071bddafbfb24ea70e0ac
21-
PinLayout: b2ebf8622b28e82b6e1216ab4e4a0a8d082214fe
21+
PinLayout: a2bbe9057d49a1e326b13dc4fe8c14751f8c8844
2222
Quick: 58d203b1c5e27fff7229c4c1ae445ad7069a7a08
2323
Reveal-SDK: 7869ddf1f902cabbb07a1f0dd06bd25861a126f7
2424
SwiftLint: e14651157288e9e01d6e1a71db7014fb5744a8ea

0 commit comments

Comments
 (0)