Created
September 2, 2015 13:19
-
-
Save macu/056d5f9af262516dc70a to your computer and use it in GitHub Desktop.
Useful modal UIViewController extensions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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