-
-
Save jajy24/f68ba30774174b0e6446 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import <UIKit/UIKit.h> | |
| @interface UIView (Recursion) | |
| /** | |
| Return YES from the block to recurse into the subview. | |
| Set stop to YES to return the subview. | |
| */ | |
| - (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse; | |
| @end | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #import "UIView+Recursion.h" | |
| @implementation UIView (Recursion) | |
| - (UIView*)findViewRecursively:(BOOL(^)(UIView* subview, BOOL* stop))recurse | |
| { | |
| for( UIView* subview in self.subviews ) { | |
| BOOL stop = NO; | |
| if( recurse( subview, &stop ) ) { | |
| return [subview findViewRecursively:recurse]; | |
| } else if( stop ) { | |
| return subview; | |
| } | |
| } | |
| return nil; | |
| } | |
| @end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment