这是我的观点代码。

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)
}

关于ios - 应用转到背景一段时间后,CoreGraphic的 View 绘制消失了,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/52269813/

10-13 04:12