Last active
April 24, 2018 07:22
-
-
Save dzenbot/f5f46283886bafa92795cceb22e4fba0 to your computer and use it in GitHub Desktop.
An easy way to detect the topmost presented view controller on iOS
This file contains 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
+ (UIViewController *)topPresentedViewController | |
{ | |
UIAppDelegate *delegate = [UIApplication sharedApplication].delegate; | |
UIViewController *visibleViewController = delegate.keyWindow.rootViewController; | |
while (visibleViewController.presentedViewController) { | |
visibleViewController = visibleViewController.presentedViewController; | |
} | |
return visibleViewController; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment