2017-04-25 1 views
0

keyWindow를 사용하여 subView를 추가하면 성공하지만 화면 계층 구조 앞에 표시되지 않았습니다.KeyWindow 추가 subView, 앞에 표시되지 않았습니다.

enter image description here

내 코드는 다음과 같습니다 : I가 작동하지 않습니다 front.But에 가져다 사용 [keywindow bringSubviewToFront:pop_v]을 시도

@interface ViewController() 
{ 
    LMLUpspringView *pop_v; 
} 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    pop_v = [[LMLUpspringView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; 

    UIWindow *keywindow = [[[UIApplication sharedApplication] delegate] window]; 

    [keywindow addSubview:pop_v]; 

    //[keywindow bringSubviewToFront:pop_v]; 
    //[self.view addSubview:pop_v]; 

} 

깊은 회색보기 내 추가 된보기입니다.

[self.view addSubview:pop_v]을 사용하면 앞에 표시됩니다.

답변

0

당신은 AppDelegate에 윈도우를 사용하여이 문제를 해결할 수 있습니다 :

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
[appDelegate.window addSubview:pop_v] 
1

당신은이 문제로 실행을의 viewDidLoad 방법과 viewDidAppear: 방법의 차이를 모르는 당신에 의해 발생합니다.

viewWillAppear : 뷰가 창문 '뷰 계층

viewDidAppear에 추가되기 전에 호출

: 뷰 후에 호출

뷰 계층 구조에 추가됩니다

컨트롤러의 뷰를 윈도우의 뷰 계층 구조에 추가하면 viewWillAppear:viewDidAppear: 사이이며 viewDidLoadviewWillAppear: 앞에 있으므로 그렇게 할 수 없습니다. viewDidAppear:보기에 추가해야합니다.

0

사용이 :

@interface ViewController() 
{ 
    LMLUpspringView *pop_v; 
} 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 

    pop_v = [[LMLUpspringView alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height)]; 

UIWindow keywindow * = [[UIApplication sharedApplication] keyWindow];

[keywindow addSubview:pop_v]; 

    //[keywindow bringSubviewToFront:pop_v]; 
    //[self.view addSubview:pop_v]; 

}