如何在 Swift 中重绘 CGRect?
How to ReDraw CGRect in Swift?
我有 UIView 子类:
ClockFace
初始化使用:
override func drawRect(rect: CGRect) {...}
在我的ViewController中表示为:
@IBOutlet weak var analogClock: ClockFace!
我重绘模拟时钟:
analogClock.drawRect(analogClock.bounds)
但是这会产生错误:
CGContextMoveToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable.
fatal error: unexpectedly found nil while unwrapping an Optional value
我做错了什么?
你可以试试analogClock.setNeedsDisplay()
我有 UIView 子类:
ClockFace
初始化使用:
override func drawRect(rect: CGRect) {...}
在我的ViewController中表示为:
@IBOutlet weak var analogClock: ClockFace!
我重绘模拟时钟:
analogClock.drawRect(analogClock.bounds)
但是这会产生错误:
CGContextMoveToPoint: invalid context 0x0. If you want to see the backtrace, please set CG_CONTEXT_SHOW_BACKTRACE environmental variable. fatal error: unexpectedly found nil while unwrapping an Optional value
我做错了什么?
你可以试试analogClock.setNeedsDisplay()