Fixes misc. iPhone X layout issues
This commit is contained in:
parent
c0ffa10fff
commit
bb418038e2
@ -1 +1 @@
|
|||||||
Subproject commit d7213260852683ea5a3f6c2274733bbd65d2ec92
|
Subproject commit dd292d6ceaa1c0543e3dd0453251379287a923a7
|
||||||
@ -23,22 +23,52 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
|
|||||||
// If only one row, distribute the items equally horizontally
|
// If only one row, distribute the items equally horizontally
|
||||||
var usesEqualHorizontalSpacingDistributionForSingleRow = false
|
var usesEqualHorizontalSpacingDistributionForSingleRow = false
|
||||||
|
|
||||||
|
private var contentInset: UIEdgeInsets {
|
||||||
|
guard let collectionView = self.collectionView else { return .zero }
|
||||||
|
|
||||||
|
var contentInset = collectionView.contentInset
|
||||||
|
if #available(iOS 11, *)
|
||||||
|
{
|
||||||
|
contentInset.left += collectionView.safeAreaInsets.left
|
||||||
|
contentInset.right += collectionView.safeAreaInsets.right
|
||||||
|
}
|
||||||
|
|
||||||
|
return contentInset
|
||||||
|
}
|
||||||
|
|
||||||
|
private var contentWidth: CGFloat {
|
||||||
|
guard let collectionView = self.collectionView else { return 0.0 }
|
||||||
|
|
||||||
|
let contentWidth = collectionView.bounds.width - (self.contentInset.left + self.contentInset.right)
|
||||||
|
return contentWidth
|
||||||
|
}
|
||||||
|
|
||||||
|
private var maximumItemsPerRow: Int {
|
||||||
|
let maximumItemsPerRow = Int(floor((self.contentWidth - self.minimumInteritemSpacing) / (self.itemWidth + self.minimumInteritemSpacing)))
|
||||||
|
return maximumItemsPerRow
|
||||||
|
}
|
||||||
|
|
||||||
|
private var interitemSpacing: CGFloat {
|
||||||
|
let interitemSpacing = (self.contentWidth - CGFloat(self.maximumItemsPerRow) * self.itemWidth) / CGFloat(self.maximumItemsPerRow + 1)
|
||||||
|
return interitemSpacing
|
||||||
|
}
|
||||||
|
|
||||||
override var estimatedItemSize: CGSize {
|
override var estimatedItemSize: CGSize {
|
||||||
didSet {
|
didSet {
|
||||||
fatalError("GridCollectionViewLayout does not support self-sizing cells.")
|
fatalError("GridCollectionViewLayout does not support self-sizing cells.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func prepare()
|
||||||
|
{
|
||||||
|
super.prepare()
|
||||||
|
|
||||||
|
self.sectionInset.left = self.interitemSpacing + self.contentInset.left
|
||||||
|
self.sectionInset.right = self.interitemSpacing + self.contentInset.right
|
||||||
|
}
|
||||||
|
|
||||||
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
|
override func layoutAttributesForElements(in rect: CGRect) -> [UICollectionViewLayoutAttributes]?
|
||||||
{
|
{
|
||||||
guard let collectionView = self.collectionView else { return nil }
|
|
||||||
|
|
||||||
let maximumItemsPerRow = floor((collectionView.bounds.width - self.minimumInteritemSpacing) / (self.itemWidth + self.minimumInteritemSpacing))
|
|
||||||
let interitemSpacing = (collectionView.bounds.width - maximumItemsPerRow * self.itemWidth) / (maximumItemsPerRow + 1)
|
|
||||||
|
|
||||||
self.sectionInset.left = interitemSpacing
|
|
||||||
self.sectionInset.right = interitemSpacing
|
|
||||||
|
|
||||||
let layoutAttributes = super.layoutAttributesForElements(in: rect)?.map({ $0.copy() }) as! [UICollectionViewLayoutAttributes]
|
let layoutAttributes = super.layoutAttributesForElements(in: rect)?.map({ $0.copy() }) as! [UICollectionViewLayoutAttributes]
|
||||||
|
|
||||||
var minimumY: CGFloat? = nil
|
var minimumY: CGFloat? = nil
|
||||||
@ -58,7 +88,7 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
|
|||||||
|
|
||||||
if abs(attributes.frame.minX - self.sectionInset.left) > 1
|
if abs(attributes.frame.minX - self.sectionInset.left) > 1
|
||||||
{
|
{
|
||||||
attributes.frame.origin.x = previousLayoutAttributes.frame.maxX + interitemSpacing
|
attributes.frame.origin.x = previousLayoutAttributes.frame.maxX + self.interitemSpacing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,7 +100,7 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
|
|||||||
{
|
{
|
||||||
isSingleRow = false
|
isSingleRow = false
|
||||||
|
|
||||||
self.alignLayoutAttributes(tempLayoutAttributes, toMinimumY: minY)
|
self.align(tempLayoutAttributes, toMinimumY: minY)
|
||||||
|
|
||||||
// Reset tempLayoutAttributes
|
// Reset tempLayoutAttributes
|
||||||
tempLayoutAttributes.removeAll()
|
tempLayoutAttributes.removeAll()
|
||||||
@ -97,15 +127,15 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
|
|||||||
// Handle the remaining tempLayoutAttributes
|
// Handle the remaining tempLayoutAttributes
|
||||||
if let minimumY = minimumY
|
if let minimumY = minimumY
|
||||||
{
|
{
|
||||||
self.alignLayoutAttributes(tempLayoutAttributes, toMinimumY: minimumY)
|
self.align(tempLayoutAttributes, toMinimumY: minimumY)
|
||||||
|
|
||||||
if isSingleRow && self.usesEqualHorizontalSpacingDistributionForSingleRow
|
if isSingleRow && self.usesEqualHorizontalSpacingDistributionForSingleRow
|
||||||
{
|
{
|
||||||
let spacing = (collectionView.bounds.width - (self.itemWidth * CGFloat(tempLayoutAttributes.count))) / (CGFloat(tempLayoutAttributes.count) + 1.0)
|
let spacing = (self.contentWidth - (self.itemWidth * CGFloat(tempLayoutAttributes.count))) / (CGFloat(tempLayoutAttributes.count) + 1.0)
|
||||||
|
|
||||||
for (index, layoutAttributes) in tempLayoutAttributes.enumerated()
|
for (index, layoutAttributes) in tempLayoutAttributes.enumerated()
|
||||||
{
|
{
|
||||||
layoutAttributes.frame.origin.x = spacing + (spacing + self.itemWidth) * CGFloat(index)
|
layoutAttributes.frame.origin.x = spacing + (spacing + self.itemWidth) * CGFloat(index) + self.contentInset.left
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -117,7 +147,7 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
|
|||||||
|
|
||||||
private extension GridCollectionViewLayout
|
private extension GridCollectionViewLayout
|
||||||
{
|
{
|
||||||
func alignLayoutAttributes(_ layoutAttributes: [UICollectionViewLayoutAttributes], toMinimumY minimumY: CGFloat)
|
func align(_ layoutAttributes: [UICollectionViewLayoutAttributes], toMinimumY minimumY: CGFloat)
|
||||||
{
|
{
|
||||||
for attributes in layoutAttributes
|
for attributes in layoutAttributes
|
||||||
{
|
{
|
||||||
|
|||||||
@ -23,6 +23,10 @@ class LaunchViewController: UIViewController
|
|||||||
return self.gameViewController?.prefersStatusBarHidden ?? false
|
return self.gameViewController?.prefersStatusBarHidden ?? false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override func childViewControllerForHomeIndicatorAutoHidden() -> UIViewController? {
|
||||||
|
return self.gameViewController
|
||||||
|
}
|
||||||
|
|
||||||
override func viewDidAppear(_ animated: Bool)
|
override func viewDidAppear(_ animated: Bool)
|
||||||
{
|
{
|
||||||
super.viewDidAppear(animated)
|
super.viewDidAppear(animated)
|
||||||
|
|||||||
@ -33,7 +33,7 @@ class PausePresentationController: UIPresentationController
|
|||||||
{
|
{
|
||||||
guard let containerView = self.containerView else { return super.frameOfPresentedViewInContainerView }
|
guard let containerView = self.containerView else { return super.frameOfPresentedViewInContainerView }
|
||||||
|
|
||||||
let frame: CGRect
|
var frame: CGRect
|
||||||
let contentHeight = self.presentedViewController.preferredContentSize.height
|
let contentHeight = self.presentedViewController.preferredContentSize.height
|
||||||
|
|
||||||
if contentHeight == 0
|
if contentHeight == 0
|
||||||
@ -44,6 +44,11 @@ class PausePresentationController: UIPresentationController
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height)
|
frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height)
|
||||||
|
|
||||||
|
if #available(iOS 11.0, *)
|
||||||
|
{
|
||||||
|
frame.origin.y -= containerView.safeAreaInsets.bottom
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return frame
|
return frame
|
||||||
|
|||||||
@ -101,7 +101,7 @@ extension SaveStatesViewController
|
|||||||
|
|
||||||
// Use dimensions that allow two cells to fill the screen horizontally with padding in portrait mode
|
// Use dimensions that allow two cells to fill the screen horizontally with padding in portrait mode
|
||||||
// We'll keep the same size for landscape orientation, which will allow more to fit
|
// We'll keep the same size for landscape orientation, which will allow more to fit
|
||||||
collectionViewLayout.itemWidth = (portraitScreenWidth - (averageHorizontalInset * 3)) / 2
|
collectionViewLayout.itemWidth = floor((portraitScreenWidth - (averageHorizontalInset * 3)) / 2)
|
||||||
|
|
||||||
switch self.mode
|
switch self.mode
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user