删除填充的NSBezierPath
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了删除填充的NSBezierPath相关的知识,希望对你有一定的参考价值。
我画了一个红圈。然后我想删除它。我怎样才能做到这一点?
class Red: NSView {
var red = 255
var green = 0
var blue = 0
override func draw(_ dirtyRect: NSRect) {
let circleFillColor = NSColor(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: 1)
let cPath: NSBezierPath = NSBezierPath(ovalIn: dirtyRect)
circleFillColor.set()
cPath.fill()
}
}
override func viewDidLoad() {
super.viewDidLoad()
let signal = Red(frame: NSRect(x: 146, y: 18, width: 25, height: 25))
self.view.addSubview(signal)
}
答案
您可以使用视图的removeFromSuperview
方法获取,如下:
class ViewController: NSViewController {
var signal: Red?
override func viewDidLoad() {
super.viewDidLoad()
self.signal = Red(frame: NSRect(x: 146, y: 18, width: 25, height: 25))
self.view.addSubview(signal!)
}
func deleteCircle() {
self.signal?.removeFromSuperview()
self.signal = nil
}
}
以上是关于删除填充的NSBezierPath的主要内容,如果未能解决你的问题,请参考以下文章
NSBezierPath 的 strokeRect: 是不是总是绘制透明矩形? (可可 OSX)