Fixes bug where presenting EditCheatViewController would mess up PausePresentationController's layout

This commit is contained in:
Riley Testut 2016-05-27 23:48:15 -05:00
parent 9b5357ccd6
commit 15ec9c9f49
2 changed files with 19 additions and 5 deletions

View File

@ -116,7 +116,7 @@ private extension CheatsViewController
@IBAction func addCheat() @IBAction func addCheat()
{ {
let editCheatViewController = self.makeEditCheatViewController(cheat: nil) let editCheatViewController = self.makeEditCheatViewController(cheat: nil)
self.presentViewController(RSTContainInNavigationController(editCheatViewController), animated: true, completion: nil) editCheatViewController.presentWithPresentingViewController(self)
} }
func deleteCheat(cheat: Cheat) func deleteCheat(cheat: Cheat)
@ -231,7 +231,7 @@ extension CheatsViewController
let editAction = UITableViewRowAction(style: .Normal, title: NSLocalizedString("Edit", comment: "")) { (action, indexPath) in let editAction = UITableViewRowAction(style: .Normal, title: NSLocalizedString("Edit", comment: "")) { (action, indexPath) in
let editCheatViewController = self.makeEditCheatViewController(cheat: cheat) let editCheatViewController = self.makeEditCheatViewController(cheat: cheat)
self.presentViewController(RSTContainInNavigationController(editCheatViewController), animated: true, completion: nil) editCheatViewController.presentWithPresentingViewController(self)
} }
return [deleteAction, editAction] return [deleteAction, editAction]
@ -261,7 +261,8 @@ extension CheatsViewController: UIViewControllerPreviewingDelegate
func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController) func previewingContext(previewingContext: UIViewControllerPreviewing, commitViewController viewControllerToCommit: UIViewController)
{ {
self.presentViewController(RSTContainInNavigationController(viewControllerToCommit), animated: true, completion: nil) let editCheatViewController = viewControllerToCommit as! EditCheatViewController
editCheatViewController.presentWithPresentingViewController(self)
} }
} }

View File

@ -163,12 +163,13 @@ extension EditCheatViewController
UIPasteboard.generalPasteboard().string = cheat.code UIPasteboard.generalPasteboard().string = cheat.code
} }
let presentingViewController = self.presentingViewController let presentingViewController = self.presentingViewController!
let editCheatAction = UIPreviewAction(title: NSLocalizedString("Edit", comment: ""), style: .Default) { (action, viewController) in let editCheatAction = UIPreviewAction(title: NSLocalizedString("Edit", comment: ""), style: .Default) { (action, viewController) in
// Delaying until next run loop prevents self from being dismissed immediately // Delaying until next run loop prevents self from being dismissed immediately
dispatch_async(dispatch_get_main_queue()) { dispatch_async(dispatch_get_main_queue()) {
presentingViewController?.presentViewController(RSTContainInNavigationController(viewController), animated: true, completion: nil) let editCheatViewController = viewController as! EditCheatViewController
editCheatViewController.presentWithPresentingViewController(presentingViewController)
} }
} }
@ -204,6 +205,18 @@ extension EditCheatViewController
} }
} }
internal extension EditCheatViewController
{
func presentWithPresentingViewController(presentingViewController: UIViewController)
{
let navigationController = RSTNavigationController(rootViewController: self)
navigationController.modalPresentationStyle = .OverFullScreen // Keeps PausePresentationController active to ensure layout is not messed up
navigationController.modalPresentationCapturesStatusBarAppearance = true
presentingViewController.presentViewController(navigationController, animated: true, completion: nil)
}
}
private extension EditCheatViewController private extension EditCheatViewController
{ {
@IBAction func updateCheatName(sender: UITextField) @IBAction func updateCheatName(sender: UITextField)