UIViewController *vc = [self getCurrentControllerByView:self needClassType:[UIViewController class]];
- (id)getCurrentControllerByView:(UIView *)view needClassType:(Class)needClassType
{
return [self traverseResponderChainForUIViewControllerByView:view needClassType:needClassType];
}
- (id)traverseResponderChainForUIViewControllerByView:(UIView *)view needClassType:(Class)needClassType
{
id nextResponder = [view nextResponder];
if ([nextResponder isKindOfClass:needClassType]) {
return nextResponder;
} else if ([nextResponder isKindOfClass:[UIView class]]) {
return [self traverseResponderChainForUIViewControllerByView:nextResponder needClassType:needClassType];
} else {
return nil;
}
}
转载请注明原文地址: https://ju.6miu.com/read-1029.html