How to get the active view in an iOS application f

2019-03-17 22:51发布

how can i get the currently active view (the main view currently being viewed by the user) from the app delegate for references sake?

8条回答
在下西门庆
2楼-- · 2019-03-17 23:38
UIWindow *window = [[UIApplication sharedApplication] keyWindow];
UIView *topView = window.rootViewController.view;
查看更多
劫难
3楼-- · 2019-03-17 23:41

I found this and it works great for me for all types of segues and view controllers.

+(UIViewController*) getTopController{
    UIViewController *topViewController = [UIApplication sharedApplication].keyWindow.rootViewController;

    while (topViewController.presentedViewController) {
        topViewController = topViewController.presentedViewController;
    }

    return topViewController;
}
查看更多
登录 后发表回答