【发布时间】:2016-11-10 19:47:56
【问题描述】:
我正在使用 Xcode 8.1
我是 UIView 的子类:
class DrawingView: UIView {
override func draw(_ rect: CGRect) {
super.draw(rect)
print("drawing...")
}
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent?) {
// re-renader the layout when finger moves
setNeedsLayout()
super.touchesMoved(touches, with: event)
}
}
当我运行我的应用程序时,上面的draw(...) 函数在应用程序启动时被调用一次。 (我看到了打印消息)
然后,我手指在屏幕上移动,我预计每次手指移动都应该调用draw(...)(因为我调用了setNeedsLayout()),
但是draw(...) 函数永远不会被调用。为什么?
【问题讨论】: