在Swift 3中的nextResponder [英] nextResponder in Swift 3
问题描述
在Swift 2中,此代码工作正常
in Swift 2 this code works fine
override func nextResponder() -> UIResponder? {
// it's called when user make any touch event
return super.nextResponder()
}
它基本上有助于获得有关任何用户交互的通知。
it's basically helps to get notification about any user interaction.
在Swift 3中现在它是一个变量而不是一个函数而我不能甚至用didSet观察它。
in Swift 3 now it's a variable not a function and I can't even observe it with didSet.
所以如何在Swift 3中使用上面的代码
so how to use the code above in Swift 3
推荐答案
你可以覆盖变量:
override var next: UIResponder? {
get {
// do something
return super.next
}
}
由于变量被定义为只读变量,因此实现 didSet
没有意义。你不应该设置这个变量。相反, UIResponder
的不同子类可以覆盖变量并返回不同的值。基类返回 nil
。
As the variable is defined as a read-only variable, implementing didSet
doesn't make sense. You're not supposed to set this variable. Instead, different subclasses of UIResponder
can override the variable and return different values. The base class returns nil
.
注意:变量名为 next $在Objective-C和早期Swift版本中的Swift 3和
nextResponder
中的c $ c>。当您在之间切换时,可以在文档中看到这一点。右栏中的Swift 和 Objective-C 。
Note: The variable is called next
in Swift 3 and nextResponder
in Objective-C and earlier Swift versions. This can be seen in the documentation when you switch between Swift and Objective-C in the right column.
这篇关于在Swift 3中的nextResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!