Improvements to resizing/reorientation
This commit is contained in:
@@ -25,8 +25,9 @@ class SwitchesViewController: UIViewController,
|
||||
UICollectionViewDelegateFlowLayout
|
||||
{
|
||||
weak var delegate: SwitchesViewControllerDelegate?
|
||||
|
||||
fileprivate var _collectionView: UICollectionView = UICollectionView(frame: CGRect.zero,
|
||||
collectionViewLayout: UICollectionViewFlowLayout())
|
||||
collectionViewLayout: UICollectionViewFlowLayout())
|
||||
fileprivate var _currentDevicesHash: Int = 0
|
||||
|
||||
static fileprivate let collectionViewDeviceSwitchCellReuseIdentifier = "DeviceSwitchReuseID"
|
||||
@@ -82,6 +83,7 @@ class SwitchesViewController: UIViewController,
|
||||
|
||||
let bounds = self.view.bounds
|
||||
_collectionView.frame = bounds
|
||||
_collectionView.collectionViewLayout.invalidateLayout()
|
||||
}
|
||||
|
||||
// MARK: API
|
||||
@@ -184,22 +186,28 @@ class SwitchesViewController: UIViewController,
|
||||
{
|
||||
let spacing = SwitchesViewController.collectionViewCellsSpacing
|
||||
let bounds = collectionView.bounds
|
||||
let boundsWidth = bounds.size.width
|
||||
var cellsPerRow: CGFloat = 0.0
|
||||
|
||||
switch (self.traitCollection.horizontalSizeClass) {
|
||||
case .regular where (bounds.size.width >= 400.0),
|
||||
.compact where (bounds.size.width >= 400.0):
|
||||
switch self.traitCollection.horizontalSizeClass {
|
||||
case .regular where boundsWidth >= 500.0,
|
||||
.compact where boundsWidth >= 500.0:
|
||||
cellsPerRow = 4.0
|
||||
|
||||
case .regular where 400.0 ... 499.99 ~= boundsWidth,
|
||||
.compact where 400.0 ... 499.99 ~= boundsWidth:
|
||||
cellsPerRow = 3.0
|
||||
break
|
||||
|
||||
case .compact:
|
||||
cellsPerRow = 2.0
|
||||
|
||||
default:
|
||||
cellsPerRow = 2.0
|
||||
}
|
||||
|
||||
let dimensions = floor((collectionView.bounds.size.width / cellsPerRow) - ((spacing * (cellsPerRow - 1.0)) / cellsPerRow))
|
||||
if (indexPath.item < ActionCell.count) {
|
||||
return CGSize(width: collectionView.bounds.size.width, height: rint(dimensions / 2.0))
|
||||
return CGSize(width: collectionView.bounds.size.width, height: rint(dimensions / 1.5))
|
||||
} else {
|
||||
return CGSize(width: dimensions, height: dimensions)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user