刚开始用swift写程序发现一些奇怪的问题
var window: UIWindow?
var navigationController: UINavigationController?
var rootViewController0: holdViewController?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame:UIScreen().bounds)
rootViewController0 = holdViewController()
window?.rootViewController = rootViewController0
window?.makeKeyAndVisible()
return true
}
这样写的话看似没什么问题。但是在holdViewController中的按钮点击事件就会无响应???什么鬼
然后控制台会报大量的错误:
[Touch] unexpected nil window in __sendSystemGestureLatentClientUpdate, _windowServerHitTestWindow:; layer =>, touch: phase: Stationary tap count: 1 force: 0.000 window: (null) view: (null) location in window: {0, 0} previous location in window: {0, 0} location in view: {0, 0} previous location in view: {0, 0}
看意思是Window的尺寸有问题啊。
window = UIWindow(frame:UIScreen().bounds)
应该写作
window = UIWindow(frame:UIScreen.main.bounds)
额,好吧。就好气啊,一堆低级错误,复制代码不靠谱啊!!!
第一天,加油!