Develop
2015.01.03 14:45
[ios] UIView 계층구조
Views 1219 Comment 0
UIViewUtility (계층구조)
// // UIView+Helper.m // UIViewExtension // // Created by KIM SUNG CHEOL on 12. 1. 9.. // Copyright (c) 2012 individual. All rights reserved. // #import "UIViewUtility.h" @implementation UIViewUtilty #pragma mark - #pragma mark 뷰계층구조 /** * @brief 레벨을 늘려가며 재귀적으로 뷰 트리를 탐색해 내려간다 * @param aView : 탐색을 시작할 뷰 * @param atIndent : 뷰 계층의 깊이 * @param into : 결과를 받을 스트링 * @return none * @remark none * @see displayViews: * @author Sungcheol Kim(skyfe79@gmail.com) */ +(void) dumpView:(UIView *)aView atIndent:(int)indent into:(NSMutableString *)outString { for(int i=0; i<indent; i++) { [outString appendString:@" "]; } [outString appendFormat:@"[%2d] %@ ", indent, [[aView class] description]]; for(UIView *view in [aView subviews]) [self dumpView:view atIndent:indent+1 into:outString]; } /** * @brief 레벨 0인 루트 뷰에서붙 트리를 재귀적으로 탐색한다 * @param aView : 탐색을 시작할 뷰 * @return NSString* : 탐색 결과 뷰의 계층 구조를 담은 문자열 * @remark none * @see dumpView:atIndent:into: * @author Sungcheol Kim(skyfe79@gmail.com) * @exeample UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; [button addSubview:[UIButton buttonWithType:UIButtonTypeCustom]]; [self.view addSubview:button]; [self.view addSubview:[UIButton buttonWithType:UIButtonTypeCustom]]; NSLog(@" %@",[self.view displayViews:self.view]); * @out [ 0] UIView [ 1] UIButton [ 2] UIButton [ 1] UIButton */ +(NSString *)displayViews:(UIView *)aView { NSMutableString *outString= [[NSMutableString alloc] init]; [self dumpView:aView atIndent:0 into:outString]; return [outString autorelease]; } #pragma mark - #pragma mark 뷰탐색 /** * @brief 뷰의 하위 뷰에 해당하는 모든 자손을 배열로 반환한다 * @param aView : 시작할 뷰 * @return NSArray : 모든 자손 뷰 배열 * @remark none * @see none * @author Sungcheol Kim(skyfe79@gmail.com) */ +(NSArray *)allSubViews:(UIView *)aView { NSArray *result = [aView subviews]; for(UIView *view in [aView subviews]) { NSArray *subviews = [UIViewUtilty allSubViews:view]; if(subviews) { result = [result arrayByAddingObjectsFromArray:subviews]; } } return result; } /** * @brief 애플리케이션의 모든 뷰를 반환한다 * @param void * @return 애플리케이션의 모든 뷰를 담은 배열 * @remark none * @see none * @author Sungcheol Kim(skyfe79@gmail.com) */ +(NSArray *)allApplicationViews { NSArray *result = [[UIApplication sharedApplication] windows]; for(UIWindow *window in [[UIApplication sharedApplication] windows]) { NSArray *subviews = [UIViewUtilty allSubViews:window]; if(subviews) { result = [result arrayByAddingObjectsFromArray:subviews]; } } return result; } /** * @brief UIWindow로부터 해당 뷰까지 부모 뷰의 배열을 반환한다 * @param aView : 경로를 얻을 뷰 * @return 경로를 담은 배열 * @remark none * @see none * @author Sungcheol Kim(skyfe79@gmail.com) */ +(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; } @end
[출처] https://github.com/skyfe79/iOSToolkit/blob/master/UIView/UIViewUtility.m
No. | Category | Subject | Author | Date | Views |
---|---|---|---|---|---|
405 | Develop | [c] 포인터 학습용 예제 소스 코드 | hooni | 2013.04.23 | 21080 |
404 | Develop | [c] 팩토리얼.. - 재귀함수 | hooni | 2003.04.23 | 9528 |
403 | Develop | [c] 팩토리얼 서버/클라이언트.. | hooni | 2003.04.23 | 17317 |
402 | Develop | [c] 패킷정보출력(경로, 패킷길이, 3hand, sync, ack..) | hooni | 2003.04.23 | 7283 |
401 | Develop | [c] 패킷 유량/프로토콜 통계 모니터링.. | hooni | 2013.04.23 | 8398 |
400 | Develop | [c] 패킷 에널라이저 예제 소스(성안당) | hooni | 2013.04.23 | 7002 |
399 | Develop | [c] 패스워드 암호화/사용자 정보 보기 | hooni | 2003.04.23 | 7040 |
398 | Develop | [c] 파일입출력, 링크리스트(linked list)를 이용한 주소록(도스용) 소스코드 1 | hooni | 2003.04.23 | 11189 |
397 | Develop | [c] 파일입출력 간단한 설명 | hooni | 2003.04.23 | 11272 |
396 | Develop | [c] 파일명 또는 특정 패턴을 적용 | hooni | 2016.08.03 | 885 |
395 | Develop | [c] 파일(int fd)에서 개행문자 단위로 읽기 by 후리자 | hooni | 2013.04.23 | 7162 |
394 | Develop | [c] 파일(File)의 연결과 연결 해제 (link, unlink, chown) | hooni | 2013.04.23 | 9555 |