gpt4 book ai didi

iphone - 使用 Storyboard时子类化 UIWindow

转载 作者:IT王子 更新时间:2023-10-29 07:53:28 24 4
gpt4 key购买 nike

我遇到了与这个问题中解释的相同的问题:

Where can I change the window my app uses from UIWindow to my own subclass "MyWindow" with storyboard?

我的问题是如何在我的应用程序委托(delegate)中实现返回“MyWindow”子类的“窗口”getter 方法?或者也许有其他方法可以将我的子类分配到我的应用程序的主窗口?

最佳答案

Storyboard项目中的

UIWindow 可以按照 Apple 的 UIApplicationDelegate 引用中的说明进行子类化:

window
When a storyboard is being used, the application must present the storyboard by adding it to a window and putting that window on-screen. The application queries this property for the window. The retained reference to the window by this property is necessary to keep the window from being released. If the value of the property is nil (the default), the application creates a generic instance of UIWindow and assign it to this property for the delegate to reference. You may implement the getter method of this protocol to provide the application with a different window.

换句话说,在您的 AppDelegate 实现中只需添加以下 getter

Objective-C

- (MyCustomWindow *)window
{
static MyCustomWindow *customWindow = nil;
if (!customWindow) customWindow = [[MyCustomWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
return customWindow;
}

swift

var customWindow: MyCustomWindow?    
var window: UIWindow? {
get {
customWindow = customWindow ?? MyCustomWindow(frame: UIScreen.mainScreen().bounds)
return customWindow
}
set { }
}

关于iphone - 使用 Storyboard时子类化 UIWindow,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10403137/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com