ios - 应用程序转到背景一段时间后,CoreGraphic 的视图绘制消失了
问题描述
这是我的观点的代码。
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
}
它工作正常。但有时进入后台一段时间后,这个视图就会消失。
***** 更多信息 *****
在 ViewController 中具有滚动更改此视图的高度的功能。更改高度约束后,调用self.view.layoutIfNeeded()
.
解决方案
您可以做的是在应用程序确实为第一个添加观察者激活时重新布局子视图,如下所示在您的控制器中
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)
}
推荐阅读
- c++ - 两个模板类相互使用作为模板参数
- linux - 使用 sed 将每列替换为不同的间距
- c++ - 注释掉部分单独声明时的不同输出
- reactjs - React Native setState 不会导致渲染
- r - 如何使用 regr.lm 任务在 mlr 中设置多项式(自定义)公式
- c - 预期为 'char *' 但参数的类型为 'char (*)[1000]'
- flutter - Transform.rotate 和 Clip 小部件不显示任何内容
- java - 如何使用 iText 和 XMLWorker 在 HTML 到 pdf 转换期间呈现特殊字符?
- java - 如何在不返回键的情况下根据条件对数组的项目进行分组?
- python - 比较不同 csv 文件中存在的值的概率