Develop
2015.01.03 14:45
[ios] UIView 계층구조
조회 수 1205 댓글 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
번호 | 분류 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|---|
445 | Develop |
[c++] 현승이가 준 P2P 프로그램 소스 ㅋㅋ
![]() |
hooni | 2013.04.23 | 12091 |
444 | Develop | [c++] BHO 프로그램 동작 원리.. 간단하게.. | hooni | 2013.04.23 | 43134 |
443 | Develop |
OPT와 CAS에 대한 자료.. (교수님 메일로 보내드린 자료..)
![]() |
hooni | 2013.04.23 | 13958 |
442 | Develop |
[doc] 테크니컬 레포트 (BHO 취약점을 이용한 공격)
2 ![]() |
hooni | 2013.04.23 | 27122 |
441 | Develop |
[doc] 유료 방송 제어 시스템 (CAS) 발표자료
![]() |
hooni | 2013.04.23 | 8518 |
440 | Develop |
[c++] 웹폼(webform)전송과 http 파일 업로드 샘플
![]() |
hooni | 2013.04.23 | 33102 |
439 | Develop | [c++] 디렉토리 내의 파일 찾기 FindFirstFile() 함수 6 | hooni | 2013.04.23 | 20634 |
438 | Develop |
[c++] 가짜 인증서(하나은행) 프로그램
![]() |
hooni | 2013.04.23 | 10769 |
437 | Develop | [js] 이미지 사이즈를 동적으로 조절.. | hooni | 2013.04.23 | 7486 |
436 | Develop |
[js] 부모창에서 자식창으로 문자열 전달..
![]() |
hooni | 2013.04.23 | 7467 |
435 | Develop |
[c#] 툴바 소스.. 개인적으로 만드는거..
![]() |
hooni | 2013.04.23 | 3304 |
434 | Develop |
[php] 그래프 그리는 프로그램..
![]() |
hooni | 2013.04.23 | 8480 |