Cannot override prefersHomeIndicatorAutoHidden() method

◇◆丶佛笑我妖孽 提交于 2021-02-07 08:47:32

问题


I use this line of code in an app with XCode 10 in order to dim the home indicator on iPhone X and associated edgeless apple devices.

    override func prefersHomeIndicatorAutoHidden() -> Bool {
        return true
    }

Now the funny thing is, I have an exact copy of this app and on one copy the code works, whilst on the over the code does not compile:

Method does not override any method from its superclass

Indeed when I start typing "prefers..." , prefersHomeIndicatorAutoHidden appears as a read-only property on the one hand, whilst it does appear as a method on the other hand, and gets the override prefix by default.

Thanks for taking the time,

Best

EDIT WITH SOLUTIONS thanks to @inokey

  • Solution 1: check deployment (starting i0S 12, prefersHomeIndicatorAutoHidden cannot be overridden as a method)

  • Solution 2 :

override var prefersHomeIndicatorAutoHidden : Bool { return true }

回答1:


I assume that default deploy target in Xcode 10 is 12 and your previous project is 11 or 10, so it just reflects the changes in API.

Changes in SDK indicate that this was changed




回答2:


in Xcode 10 = Swift 4.2 (Sep 2018)

Just use the code below:

override var prefersHomeIndicatorAutoHidden: Bool { return true }


来源:https://stackoverflow.com/questions/52387158/cannot-override-prefershomeindicatorautohidden-method

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!