2011-12-31 4 views
0

내가 새로운 UIWindow를 생성하고 팝 오버보기 같은 창에서보기를 표시 할 작동하지 않는,하지만 그것은 표시되지 않습니다makeKeyWindowAndVisible

코드 (코드는 내가 참조 SVProgressHUD 읽기)는 다음과 같습니다 :

@interface PopoverView() 

@property (nonatomic, assign) UIWindow *prevKeyWindow; 

@end 


@implementation PopoverView 

@synthesize items=_items; 
@synthesize prevKeyWindow; 

- (id)initWithFrame:(CGRect)frame 
{ 
    self = [super initWithFrame:[[UIScreen mainScreen] bounds]]; 
    if (self) { 
     self.windowLevel = UIWindowLevelAlert; 
     // Initialization code 
     UILabel *view = [[UILabel alloc] initWithFrame:frame]; 
     view.backgroundColor = [UIColor blackColor]; 
     [self addSubview:view]; 
     self.backgroundColor = [UIColor blackColor]; 
     self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; 
    } 
    return self; 
} 

- (void)show { 
    if (![self isKeyWindow]) { 
     self.prevKeyWindow = [UIApplication sharedApplication].keyWindow; 
     [self makeKeyAndVisible]; 
    } 
} 

@end 

누구든지 도움이하는 .m 파일에서 .H 파일

#import <UIKit/UIKit.h> 

@interface PopoverView : UIWindow 

@property (nonatomic, strong) NSArray *items; 

- (void)show; 

@end 

에서

?

+0

- (void) show { if (! [self isKeyWindow]) { self.prevKeyWindow = [UIApplication sharedApplication] .keyWindow; [self makeKeyAndVisible]; } }이 코드를 응용 프로그램 위임 파일에 제공해야합니다. 내 말은 어디에서 창을 초기화할까요? –

+0

이제 팝 오버처럼 보이는 창을 표시하려고합니다. 작동하지 않습니다. 시도해 보지 않았습니다. 모두 가장 좋은 답변입니다. –

+0

다음은 초기화 코드입니다. 'PopoverView * pop = [[PopoverView alloc] initWithFrame : CGRectMake (40, 40, 80, 80)]; [pop show];' –

답변

0

PopoverView 변수는 전역 변수 여야합니다. 로컬 변수 인 경우 UIWindow가 파괴되어 표시되지 않고 매우 빠르게 사라집니다.