Displays dummy data in SaveStatesViewController

This commit is contained in:
Riley Testut 2016-01-31 03:10:39 -08:00
parent 9dcec258c1
commit 544f1a1801
8 changed files with 104 additions and 5 deletions

View File

@ -50,6 +50,7 @@ class GridCollectionViewCell: UICollectionViewCell
self.contentView.clipsToBounds = false
self.imageView.translatesAutoresizingMaskIntoConstraints = false
self.imageView.contentMode = .ScaleAspectFit
#if os(tvOS)
self.imageView.adjustsImageWhenAncestorFocused = true
#endif
@ -135,7 +136,7 @@ private extension GridCollectionViewCell
self.imageViewWidthConstraint.constant = self.maximumImageSize.width
self.imageViewHeightConstraint.constant = self.maximumImageSize.height
self.textLabelVerticalSpacingConstraint.constant = self.maximumImageSize.height / 10.0
self.textLabelVerticalSpacingConstraint.constant = 8
self.textLabelFocusedVerticalSpacingConstraint?.constant = self.maximumImageSize.height / 10.0
}
}

View File

@ -12,7 +12,11 @@ class GridCollectionViewLayout: UICollectionViewFlowLayout
{
var itemWidth: CGFloat = 150 {
didSet {
self.invalidateLayout()
// Only invalidate if needed, otherwise could potentially cause endless loop
if oldValue != self.itemWidth
{
self.invalidateLayout()
}
}
}

View File

@ -39,13 +39,19 @@ class PausePresentationController: UIPresentationController
{
guard let containerView = self.containerView else { return super.frameOfPresentedViewInContainerView() }
var contentHeight = self.presentedViewController.preferredContentSize.height
let frame: CGRect
let contentHeight = self.presentedViewController.preferredContentSize.height
if contentHeight == 0
{
contentHeight = containerView.bounds.height - UIApplication.sharedApplication().statusBarFrame.height
let statusBarHeight = UIApplication.sharedApplication().statusBarFrame.height
frame = CGRect(x: 0, y: statusBarHeight, width: containerView.bounds.width, height: containerView.bounds.height - statusBarHeight)
}
else
{
frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height)
}
let frame = CGRect(x: 0, y: containerView.bounds.height - contentHeight, width: containerView.bounds.width, height: containerView.bounds.height)
return frame
}

View File

@ -10,21 +10,45 @@ import UIKit
import Roxas
private let SaveStatesViewControllerContentInset: CGFloat = 20
class SaveStatesViewController: UICollectionViewController
{
private var backgroundView: RSTBackgroundView!
private var prototypeCell = GridCollectionViewCell()
private var prototypeCellWidthConstraint: NSLayoutConstraint!
}
extension SaveStatesViewController
{
override func viewDidLoad()
{
super.viewDidLoad()
self.backgroundView = RSTBackgroundView(frame: self.view.bounds)
self.backgroundView.hidden = true
self.backgroundView.autoresizingMask = [.FlexibleWidth, .FlexibleHeight]
self.backgroundView.textLabel.text = NSLocalizedString("No Save States", comment: "")
self.backgroundView.textLabel.textColor = UIColor.whiteColor()
self.backgroundView.detailTextLabel.text = NSLocalizedString("You can create a new save state by pressing the + button in the top right.", comment: "")
self.backgroundView.detailTextLabel.textColor = UIColor.whiteColor()
self.view.insertSubview(self.backgroundView, atIndex: 0)
// We update the layout in code because we need to use our SaveStatesViewControllerContentInset constant
// The reason for this is we cannot query the layout for its sectionInset in viewDidLayoutSubviews, so might as well be explicit in code with a constant
// Otherwise, we could configure this all in Interface Builder, but we'd still need to hardcode 20 in for viewDidLayoutSubviews
let collectionViewLayout = self.collectionViewLayout as! GridCollectionViewLayout
collectionViewLayout.sectionInset = UIEdgeInsets(top: SaveStatesViewControllerContentInset, left: SaveStatesViewControllerContentInset, bottom: SaveStatesViewControllerContentInset, right: SaveStatesViewControllerContentInset)
collectionViewLayout.minimumInteritemSpacing = SaveStatesViewControllerContentInset
collectionViewLayout.minimumLineSpacing = SaveStatesViewControllerContentInset
let portraitScreenWidth = UIScreen.mainScreen().coordinateSpace.convertRect(UIScreen.mainScreen().bounds, toCoordinateSpace: UIScreen.mainScreen().fixedCoordinateSpace).width
collectionViewLayout.itemWidth = (portraitScreenWidth - ((SaveStatesViewControllerContentInset) * 3)) / 2
// Manually update prototype cell properties
self.prototypeCellWidthConstraint = self.prototypeCell.contentView.widthAnchor.constraintEqualToConstant(collectionViewLayout.itemWidth)
self.prototypeCellWidthConstraint.active = true
}
override func didReceiveMemoryWarning()
@ -32,3 +56,44 @@ class SaveStatesViewController: UICollectionViewController
super.didReceiveMemoryWarning()
}
}
private extension SaveStatesViewController
{
func configureCollectionViewCell(cell: GridCollectionViewCell, forIndexPath indexPath: NSIndexPath)
{
cell.imageView.backgroundColor = UIColor.whiteColor()
cell.imageView.image = UIImage(named: "DeltaPlaceholder")
cell.maximumImageSize = CGSizeMake(self.prototypeCellWidthConstraint.constant, (self.prototypeCellWidthConstraint.constant / 4.0) * 3.0)
cell.textLabel.textColor = UIColor.whiteColor()
cell.textLabel.font = UIFont.preferredFontForTextStyle(UIFontTextStyleSubheadline)
cell.textLabel.text = "Save State"
}
}
extension SaveStatesViewController
{
override func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
{
return 12
}
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell
{
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(RSTGenericCellIdentifier, forIndexPath: indexPath) as! GridCollectionViewCell
self.configureCollectionViewCell(cell, forIndexPath: indexPath)
return cell
}
}
extension SaveStatesViewController: UICollectionViewDelegateFlowLayout
{
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize
{
self.configureCollectionViewCell(self.prototypeCell, forIndexPath: indexPath)
let size = self.prototypeCell.contentView.systemLayoutSizeFittingSize(UILayoutFittingCompressedSize)
return size
}
}

View File

@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "universal",
"filename" : "DeltaPlaceholder.png",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "DeltaPlaceholder@2x.png",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "DeltaPlaceholder@3x.png",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 19 KiB