文章目录
需求
获取当前显示view的Controller
几个概念
visibleViewController 和 topViewController
topViewController代表当前navigation栈中最上层的VC
visibleViewController代表当前可见的VC,它可能是topViewController,也可能是当前topViewController present出来的VC
presentedViewController 和 presentingViewController
presentedViewController:The view controller that is presented by this view controlller(read-only),被本视图控制器present出来的的视图控制器presentingViewController:The view controller that presented this view controller. (read-only),present出来本视图控制器的视图控制器
例如:如A–>弹出B, 则A.presentedViewController = B
B.presentingViewController = A
思路
- APP的架构通常是 UITabBarViewController -> UINavigationController -> UIViewController
- 最后获取UINavigationController的visibleViewController
- present的情况(包括多次present)
代码
- (UIViewController *)getCurrentVC
{