ios – UIWindow?没有名为bounds的成员

ios – UIWindow?没有名为bounds的成员,第1张

概述我正在尝试更新PKHUD( https://github.com/pkluz/PKHUD)以使用Xcode 6 beta 5,除了一个小细节之外我几乎要通过: internal class Window: UIWindow { required internal init(coder aDecoder: NSCoder!) { super.init(coder: aDeco 我正在尝试更新PKHUD( https://github.com/pkluz/PKHUD)以使用Xcode 6 beta 5,除了一个小细节之外我几乎要通过:

internal class Window: UIWindow {    required internal init(coder aDecoder: NSCoder!) {        super.init(coder: aDecoder)    }    internal let frameVIEw: FrameVIEw    internal init(frameVIEw: FrameVIEw = FrameVIEw()) {        self.frameVIEw = frameVIEw        // this is the line that bombs        super.init(frame: UIApplication.sharedApplication().delegate.window!.bounds)        rootVIEwController = WindowRootVIEwController()        windowLevel = UIWindowLevelnormal + 1.0        backgroundcolor = UIcolor.clearcolor()        addSubvIEw(backgroundVIEw)        addSubvIEw(frameVIEw)    }    // more code here}

Xcode给我错误UIWindow?没有名为’bounds’的成员.
我很确定这是一个与打字有关的微不足道的错误,但我几个小时都找不到答案.

此外,此错误仅发生在Xcode 6 beta 5中,这意味着答案在于Apple最近更改的内容.

非常感谢所有帮助.

解决方法 UIApplicationDelegate协议中window属性的声明
改变了

optional var window: UIWindow! { get set } // beta 4

optional var window: UIWindow? { get set } // beta 5

这意味着它是一个可选属性,产生一个可选的UIWindow:

println(UIApplication.sharedApplication().delegate.window)// Optional(Optional(<UIWindow: 0x7f9a71717fd0; frame = (0 0; 320 568); ... >))

所以你必须打开它两次:

let bounds = UIApplication.sharedApplication().delegate.window!!.bounds

或者,如果您想检查应用程序代表的可能性
没有窗口属性,或者设置为nil:

if let bounds = UIApplication.sharedApplication().delegate.window??.bounds {} else {    // report error}

更新:使用Xcode 6.3,委托属性现在也是
定义为可选,所以代码现在是

let bounds = UIApplication.sharedApplication().delegate!.window!!.bounds

要么

if let bounds = UIApplication.sharedApplication().delegate?.window??.bounds {} else {    // report error}

有关更多解决方案,另请参见Why is main window of type double optional?.

总结

以上是内存溢出为你收集整理的ios – UIWindow?没有名为bounds的成员全部内容,希望文章能够帮你解决ios – UIWindow?没有名为bounds的成员所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1067487.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-26
下一篇 2022-05-26

发表评论

登录后才能评论

评论列表(0条)

保存