新手警告!: ) 我的应用程序中有多个视图,所有视图都设置在故事板中,并且都有自己的子类 UIView 类和自己的覆盖 drawRect 方法。其中一个用作按钮,并且能够通过 setneedsdisplay 重绘自身并调用另一个 UIViews 类的函数:
import UIKit
class Button: UIView {
override func touchesEnded(touches: NSSet, withEvent event: UIEvent) {
super.touchesEnded(touches, withEvent: event)
let touchPoint: CGPoint! = touches.anyObject()?.locationInView(self)
if butouched == true{
if touchPoint.x > bounds.size.width - bounds.size.height && touchPoint.x < bounds.size.width && touchPoint.y > 0 && touchPoint.y < bounds.size.height{
counter++
setNeedsDisplay() //thats the setNeedsDisplay that works
DrawGraph().updateModell()
}
}
}
现在的问题是该函数中的 setNeedsDisplay 不起作用,即使调用了 updateModell 函数:
import UIKit
class DrawGraph: UIView {
func updateModell() {
setNeedsDisplay() // thats the setNeedsDisplay that doesn't work
}
所以我用谷歌搜索和搜索,但就是不知道出了什么问题。是的,这是我使用 Swift 和 iOS 的第一周……