To create a new UIWindow over the main window

后端 未结 8 2379

In my app I want to create a new UIWindow over the main UIWindow, And I wrote as following, but it don\'t works. first, i create a UIWindow as the

8条回答
  •  时光取名叫无心
    2020-12-07 23:00

    UIWindow *window1 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 320)];
    window1.backgroundColor = [UIColor redColor];
    window1.windowLevel = UIWindowLevelAlert;
    [window1 makeKeyAndVisible];
    

    Finally I know why it doesn't work, because window1 is a method var, and it will lost after the method executed. So I declare a new @property for it, as

    @property (strong, nonatomic) UIWindow *window2;
    

    and change the code like

    UIWindow *window2 = [[UIWindow alloc] initWithFrame:CGRectMake(0, 80, 320, 320)];
    window2.backgroundColor = [UIColor redColor];
    window2.windowLevel = UIWindowLevelAlert;
    self.window2 = window2;
    [window2 makeKeyAndVisible];
    

    it works!

提交回复
热议问题