diff --git a/Common/Collection View/GridCollectionViewCell.swift b/Common/Collection View/GridCollectionViewCell.swift index 3261974..f88bc2b 100644 --- a/Common/Collection View/GridCollectionViewCell.swift +++ b/Common/Collection View/GridCollectionViewCell.swift @@ -13,12 +13,40 @@ class GridCollectionViewCell: UICollectionViewCell let imageView = UIImageView() let textLabel = UILabel() + var isImageViewVibrancyEnabled = true { + didSet { + if self.isImageViewVibrancyEnabled + { + self.vibrancyView.contentView.addSubview(self.imageView) + } + else + { + self.contentView.addSubview(self.imageView) + } + } + } + + var isTextLabelVibrancyEnabled = true { + didSet { + if self.isTextLabelVibrancyEnabled + { + self.vibrancyView.contentView.addSubview(self.textLabel) + } + else + { + self.contentView.addSubview(self.textLabel) + } + } + } + var maximumImageSize: CGSize = CGSize(width: 100, height: 100) { didSet { self.updateMaximumImageSize() } } + private var vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .dark))) + private var imageViewWidthConstraint: NSLayoutConstraint! private var imageViewHeightConstraint: NSLayoutConstraint! @@ -49,20 +77,37 @@ class GridCollectionViewCell: UICollectionViewCell self.clipsToBounds = false self.contentView.clipsToBounds = false - self.imageView.translatesAutoresizingMaskIntoConstraints = false + self.vibrancyView.translatesAutoresizingMaskIntoConstraints = false + self.vibrancyView.contentView.translatesAutoresizingMaskIntoConstraints = false + self.contentView.addSubview(self.vibrancyView) + self.imageView.contentMode = .scaleAspectFit #if os(tvOS) self.imageView.adjustsImageWhenAncestorFocused = true #endif self.contentView.addSubview(self.imageView) - self.textLabel.translatesAutoresizingMaskIntoConstraints = false self.textLabel.font = UIFont.boldSystemFont(ofSize: 12) self.textLabel.textAlignment = .center self.textLabel.numberOfLines = 0 self.contentView.addSubview(self.textLabel) - // Auto Layout + /* Auto Layout */ + + // Vibrancy View + // Need to add explicit constraints for vibrancyView + vibrancyView.contentView or else Auto Layout won't calculate correct size 🙄 + self.vibrancyView.topAnchor.constraint(equalTo: self.contentView.topAnchor).isActive = true + self.vibrancyView.bottomAnchor.constraint(equalTo: self.contentView.bottomAnchor).isActive = true + self.vibrancyView.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor).isActive = true + self.vibrancyView.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor).isActive = true + + self.vibrancyView.contentView.topAnchor.constraint(equalTo: self.vibrancyView.topAnchor).isActive = true + self.vibrancyView.contentView.bottomAnchor.constraint(equalTo: self.vibrancyView.bottomAnchor).isActive = true + self.vibrancyView.contentView.leadingAnchor.constraint(equalTo: self.vibrancyView.leadingAnchor).isActive = true + self.vibrancyView.contentView.trailingAnchor.constraint(equalTo: self.vibrancyView.trailingAnchor).isActive = true + + // Image View + self.imageView.translatesAutoresizingMaskIntoConstraints = false self.imageView.topAnchor.constraint(equalTo: self.contentView.topAnchor).isActive = true self.imageView.centerXAnchor.constraint(equalTo: self.contentView.centerXAnchor).isActive = true @@ -74,6 +119,9 @@ class GridCollectionViewCell: UICollectionViewCell self.imageViewHeightConstraint.isActive = true + // Text Label + self.textLabel.translatesAutoresizingMaskIntoConstraints = false + self.textLabel.trailingAnchor.constraint(equalTo: self.contentView.trailingAnchor).isActive = true self.textLabel.leadingAnchor.constraint(equalTo: self.contentView.leadingAnchor).isActive = true @@ -96,7 +144,7 @@ class GridCollectionViewCell: UICollectionViewCell self.updateMaximumImageSize() } - + override func didUpdateFocus(in context: UIFocusUpdateContext, with coordinator: UIFocusAnimationCoordinator) { super.didUpdateFocus(in: context, with: coordinator) @@ -125,7 +173,7 @@ class GridCollectionViewCell: UICollectionViewCell self.layoutIfNeeded() - }, completion: nil) + }, completion: nil) } } diff --git a/Delta/Base.lproj/PauseMenu.storyboard b/Delta/Base.lproj/PauseMenu.storyboard index 0ab5e34..17646a9 100644 --- a/Delta/Base.lproj/PauseMenu.storyboard +++ b/Delta/Base.lproj/PauseMenu.storyboard @@ -1,8 +1,8 @@ - + - + @@ -24,34 +24,17 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + - - - - + + + + @@ -199,7 +182,7 @@ - + @@ -236,10 +219,10 @@ - + - + @@ -264,10 +247,10 @@ - + - + @@ -292,10 +275,10 @@ - + - + diff --git a/Delta/Pause Menu/PauseMenuViewController.swift b/Delta/Pause Menu/PauseMenuViewController.swift index cf7269c..954b6f5 100644 --- a/Delta/Pause Menu/PauseMenuViewController.swift +++ b/Delta/Pause Menu/PauseMenuViewController.swift @@ -88,6 +88,9 @@ private extension PauseMenuViewController cell.imageView.tintColor = UIColor.white cell.imageView.backgroundColor = UIColor.clear } + + cell.isImageViewVibrancyEnabled = true + cell.isTextLabelVibrancyEnabled = true } func toggleSelectedStateForPauseItemAtIndexPath(_ indexPath: IndexPath) diff --git a/Delta/Pause Menu/PauseViewController.swift b/Delta/Pause Menu/PauseViewController.swift index 4510920..d5a2d25 100644 --- a/Delta/Pause Menu/PauseViewController.swift +++ b/Delta/Pause Menu/PauseViewController.swift @@ -68,14 +68,6 @@ class PauseViewController: UIViewController, PauseInfoProviding extension PauseViewController { - override func viewDidLayoutSubviews() - { - super.viewDidLayoutSubviews() - - // Ensure navigation bar is always positioned correctly despite being outside the navigation controller's view - self.pauseNavigationController.navigationBar.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.pauseNavigationController.navigationBar.bounds.height) - } - override func targetViewController(forAction action: Selector, sender: AnyObject?) -> UIViewController? { return self.pauseNavigationController @@ -96,9 +88,6 @@ extension PauseViewController let pauseMenuViewController = self.pauseNavigationController.topViewController as! PauseMenuViewController pauseMenuViewController.items = self.pauseItems - // Keep navigation bar outside the UIVisualEffectView's - self.view.addSubview(self.pauseNavigationController.navigationBar) - case "saveStates": let saveStatesViewController = segue.destination as! SaveStatesViewController saveStatesViewController.delegate = self.saveStatesViewControllerDelegate diff --git a/Delta/Pause Menu/Save States/SaveStatesCollectionHeaderView.swift b/Delta/Pause Menu/Save States/SaveStatesCollectionHeaderView.swift index 37f4ae5..cc691a6 100644 --- a/Delta/Pause Menu/Save States/SaveStatesCollectionHeaderView.swift +++ b/Delta/Pause Menu/Save States/SaveStatesCollectionHeaderView.swift @@ -28,6 +28,11 @@ class SaveStatesCollectionHeaderView: UICollectionReusableView private func initialize() { + let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .dark))) + vibrancyView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + vibrancyView.frame = CGRect(x: 0, y: 0, width: self.bounds.width, height: self.bounds.height) + self.addSubview(vibrancyView) + self.textLabel.translatesAutoresizingMaskIntoConstraints = false self.textLabel.textColor = UIColor.white @@ -36,7 +41,7 @@ class SaveStatesCollectionHeaderView: UICollectionReusableView self.textLabel.font = UIFont(descriptor: fontDescriptor, size: 0.0) self.textLabel.textAlignment = .center - self.addSubview(self.textLabel) + vibrancyView.contentView.addSubview(self.textLabel) // Auto Layout NSLayoutConstraint.activate(NSLayoutConstraint.constraints(withVisualFormat: "H:|-20-[textLabel]-20-|", options: [], metrics: nil, views: ["textLabel": self.textLabel])) diff --git a/Delta/Pause Menu/Save States/SaveStatesViewController.swift b/Delta/Pause Menu/Save States/SaveStatesViewController.swift index d8f91e7..dda0fed 100644 --- a/Delta/Pause Menu/Save States/SaveStatesViewController.swift +++ b/Delta/Pause Menu/Save States/SaveStatesViewController.swift @@ -84,13 +84,18 @@ extension SaveStatesViewController { super.viewDidLoad() - self.backgroundView = RSTBackgroundView(frame: self.view.bounds) + let vibrancyView = UIVisualEffectView(effect: UIVibrancyEffect(blurEffect: UIBlurEffect(style: .dark))) + vibrancyView.autoresizingMask = [.flexibleWidth, .flexibleHeight] + vibrancyView.frame = CGRect(x: 0, y: 0, width: self.view.bounds.width, height: self.view.bounds.height) + self.view.insertSubview(vibrancyView, at: 0) + + self.backgroundView = RSTBackgroundView(frame: CGRect(x: 0, y: 0, width: vibrancyView.bounds.width, height: vibrancyView.bounds.height)) self.backgroundView.isHidden = true self.backgroundView.autoresizingMask = [.flexibleWidth, .flexibleHeight] self.backgroundView.textLabel.text = NSLocalizedString("No Save States", comment: "") self.backgroundView.textLabel.textColor = UIColor.white self.backgroundView.detailTextLabel.textColor = UIColor.white - self.view.insertSubview(self.backgroundView, at: 0) + vibrancyView.contentView.addSubview(self.backgroundView) let collectionViewLayout = self.collectionViewLayout as! GridCollectionViewLayout let averageHorizontalInset = (collectionViewLayout.sectionInset.left + collectionViewLayout.sectionInset.right) / 2 @@ -188,6 +193,9 @@ private extension SaveStatesViewController cell.imageView.backgroundColor = UIColor.white cell.imageView.image = UIImage(named: "DeltaPlaceholder") + cell.isTextLabelVibrancyEnabled = true + cell.isImageViewVibrancyEnabled = true + if !ignoreOperations { let imageOperation = LoadImageOperation(URL: saveState.imageFileURL) @@ -198,6 +206,8 @@ private extension SaveStatesViewController { cell.imageView.backgroundColor = nil cell.imageView.image = image + + cell.isImageViewVibrancyEnabled = false } }