1.新創(chuàng)建的UIWindow不需要添加到任何父控件上就能顯示出來(需保證創(chuàng)建的window不銷毀,用屬性強(qiáng)引用)
2.window有級(jí)別:UIWindowLevelNormal < UIWindowLevelStatusBar < UIWindowLevelAlert
級(jí)別越高的window越顯示在上面
級(jí)別相等的window,后面顯示的window顯示在上面
3.窗口要不設(shè)根控制器會(huì)報(bào)錯(cuò),可以采用延時(shí)來避免報(bào)錯(cuò)
報(bào)錯(cuò):
Application windows are expected to have a root view controller at the end of application launch
延時(shí):
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
self.topWindow = [[UIWindow alloc] init];
// self.topWindow.frame = application.statusBarFrame;
self.topWindow.frame = CGRectMake(280, 500, 80, 80);
self.topWindow.backgroundColor = [UIColor redColor];
self.topWindow.windowLevel = UIWindowLevelAlert;
self.topWindow.hidden = NO;
[self.topWindow addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(click)]];
});
可能的應(yīng)用場(chǎng)景:電商的購(gòu)物車(全程一直顯示在最外層)