- // Return an exhaustive descent of the view's subviews
- NSArray *allSubviews(UIView *aView)
- {
- NSArray *results = [aView subviews];
- for (UIView *eachView in [aView subviews]) {
-  NSArray *riz = allSubviews(eachView);
- if (riz) results = [results arrayByAddingObjectsFromArray:riz];
- }
- return results;
- }
- // Return all views throughout the application
- NSArray *allApplicationViews()
- {
- NSArray *results = [[UIApplication sharedApplication] windows];
- for (UIWindow *window in [[UIApplication sharedApplication]windows]) {
- NSArray *riz = allSubviews(window);
- if (riz) results = [results arrayByAddingObjectsFromArray:riz];
- }
- return results;
- }
- // Return an array of parent views from the window down to the view
- NSArray *pathToView(UIView *aView)
- {
- NSMutableArray *array = [NSMutableArray arrayWithObject:aView];
- UIView *view = aView;
- UIWindow *window = aView.window;
- while (view != window)
- {
- view = [view superview];
- [array insertObject:view atIndex:0];
- }
- return array;
- }
- //该片段来自于http://www.codesnippet.cn/detail/111220137955.html
来源: http://www.codesnippet.cn/detail/111220137955.html