显示另一个UIWindow的麻烦

Dan*_*row 3 uiwindow ipad ios

我正在写一个iPad应用程序,我正试图UIWindow在我的应用程序的主窗口顶部显示第二个.我要做的主要是创建一个登录窗口(如何使用UISplitViewController呈现登录?),似乎在这里创建第二个窗口可能是一个不错的选择.

我做了一个非常简单的应用程序试试这个.当用户点击按钮时,我正试图显示第二个窗口.这是代码:

- (IBAction)showOtherWindow:(id)sender {
    UIWindow* otherWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    otherWindow.hidden = NO;
    otherWindow.clipsToBounds = YES;
    otherWindow.windowLevel = UIWindowLevelStatusBar;
    otherWindow.backgroundColor = [UIColor redColor];
    [otherWindow makeKeyAndVisible];
}
Run Code Online (Sandbox Code Playgroud)

我期待在这里看到一个大红色屏幕,但这不会发生 - 没有任何变化.最后,我想让一个较小的窗户浮在上面.但是现在我只想看到一个窗口.

Aar*_*den 25

如果您使用的是ARC代码,则showOtherWindow:返回后会立即取消分配窗口.尝试分配otherWindow持久对象中的ivar.