Skip to content

Instantly share code, notes, and snippets.

@macu
Created September 2, 2015 13:19
Show Gist options
  • Select an option

  • Save macu/056d5f9af262516dc70a to your computer and use it in GitHub Desktop.

Select an option

Save macu/056d5f9af262516dc70a to your computer and use it in GitHub Desktop.
Useful modal UIViewController extensions.
import Foundation
import UIKit
extension UIViewController {
/// Whether the view is currently displayed in modal style.
var isModal: Bool {
return self.presentingViewController?.presentedViewController == self
|| self.navigationController?.presentingViewController?.presentedViewController == self.navigationController
|| self.tabBarController?.presentingViewController?.isKindOfClass(UITabBarController) == true
}
/// Whether the view has the same frame as the window.
/// Use this to test whether a modal fills the screen.
var hasSameFrameAsWindow: Bool {
let frame = self.view.frame
let frameInWindow = self.view.window!.convertRect(frame, fromView: self.view)
return frame == frameInWindow
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment