// // UIView+ViewController.m // neutralWatch // // Created by WeiChaoZheng on 2017/12/29. // Copyright © 2017年 xTT. All rights reserved. // #import "UIView+ViewController.h" @implementation UIView (ViewController) - (UIViewController*)getViewController{ UIViewController *viewController = nil; UIResponder *next = self.nextResponder; while (next) { if ([next isKindOfClass:[UIViewController class]]) { viewController = (UIViewController *)next; break; } next = next.nextResponder; } return viewController; } -(NSInteger)getInSuperViewIndex{ NSArray *tempArr = [self superview].subviews; for (int i = 0; i < tempArr.count; i++) { UIView *tempView = (UIView*)tempArr[i]; if([tempView isEqual:self]){ return i; } } return -1; } @end