makeKeyWindowAndVisible 不起作用
我创建一个新的 UIWindow 并想在窗口中显示一个视图,如弹出视图,但它没有显示。(我阅读的代码 SVProgressHUD 以供参考)
代码如下:
在 .h 文件中
#import <UIKit/UIKit.h>
@interface PopoverView : UIWindow
@property (nonatomic, strong) NSArray *items;
- (void)show;
@end
在 .m 文件中
@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
有人帮忙吗?
I create a new UIWindow and want to show a view in the window like popover view, but It do not show up.(The code I read SVProgressHUD for reference)
the code is below:
In .h file
#import <UIKit/UIKit.h>
@interface PopoverView : UIWindow
@property (nonatomic, strong) NSArray *items;
- (void)show;
@end
In .m file
@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
Anyone help?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
PopoverView变量必须是全局变量,如果是局部变量,UIWindow将被销毁,所以你看不到它(很快出现和消失)。
The PopoverView variable must be a global variable, if it's a local variable, the UIWindow will be destroyed, so you can't see it(appeared and disappeared very quickly).