这是我的观点的代码。
override func draw(_ rect: CGRect) {
let path = self.getPath()
path.stroke()
}
func getPath() -> UIBezierPath {
let path = UIBezierPath()
path.lineWidth = 1
path.lineCapStyle = .round
path.lineJoinStyle = .round
mainColor.setStroke()
mainColor.setFill()
path.move(to: CGPoint(x:0,y:0))
path.addQuadCurve(to: endPointLeft, controlPoint: controlPointLeft)
path.addLine(to: startPointRight)
path.addQuadCurve(to: endPointRight, controlPoint: controlPointRight)
path.addLine(to: startPointLeft)
path.fill()
path.stroke()
return path
}
效果很好。但有时进入后台一段时间后,该 View 就会消失。
*****更多信息*****
ViewController 有一个功能,可以通过滚动来改变 View 的高度。
改变高度约束后,调用self.view.layoutIfNeeded()
。
最佳答案
您可以做的是当应用程序确实为第一个添加观察者激活时重新布局 subview ,如下所示在 Controller 中
override func viewDidLoad() {
super.viewDidLoad()
NotificationCenter.default.addObserver(self, selector: #selector(applicationDidBecomeActive(_:)), name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
}
@objc func applicationDidBecomeActive(_ notification:Notification)
{
self.view.layoutIfNeeded()
}
override func viewWillDisappear(_ animated: Bool) {
NotificationCenter.default.removeObserver(self, name: NSNotification.Name.UIApplicationDidBecomeActive, object: nil)
}
关于ios - 应用程序转到后台一段时间后,CoreGraphic 绘制的 View 消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52269813/