Develop
2015.01.03 14:45

[ios] UIView 계층구조

조회 수 2317 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

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

?

List of Articles
번호 분류 제목 글쓴이 날짜 조회 수
715 Develop [ppt] iOS 플라랩#04(2015.06.19) 발표 자료 file hooni 2015.06.04 1549
714 Develop Aspect Oriented Programming in Objective-C hooni 2015.05.18 3252
713 Develop [ios] 설정에서 푸시 알림(APNS) on/off 상태 확인 hooni 2015.04.28 3581
712 Develop [ios] GPS 이용 상태 확인 hooni 2015.04.27 2934
711 Develop [js] jQuery, Javascript 모바일(스마트폰) 판단하는 방법 hooni 2015.04.26 3790
710 Develop [js] e.stopPropagation() VS e.preventDefault () file hooni 2015.04.14 1745
709 Develop [js] 모바일 스크롤 방지(해제) hooni 2015.04.14 3044
708 Develop [js] 스크롤 이벤트 막기 hooni 2015.04.14 2068
707 Develop [ios] 앱에서 설정화면 호출하기 hooni 2015.04.07 1742
706 Develop [ios] GMT Date와 Local Date 변환하기 hooni 2015.04.07 3382
705 Develop [ios] 아이폰 앱 이름 및 버전 정보 hooni 2015.03.24 2194
704 Develop [ios] 카메라 사용 권한 확인해서 분기하는 방법 hooni 2015.02.26 2883
703 Develop [ios] Touch ID 적용 샘플 코드 (예제) file hooni 2015.02.23 1832
702 Develop [펌] 게임 엔진 만든거 공개합니다. hooni 2015.02.21 3785
701 Develop [ios] StoryBoard(xib) 없이 프로젝트 만들기 file hooni 2015.02.12 2228
700 Develop [ios] UIWebView에서 로컬에 있는 html 파일 불러오기 hooni 2015.02.10 1998
Board Pagination Prev 1 ... 7 8 9 10 11 ... 53 Next
/ 53