gpt4 book ai didi

ios - UIImage.DrawInRect 导致错误/通知

转载 作者:行者123 更新时间:2023-11-29 02:40:20 25 4
gpt4 key购买 nike

创建一个简单的应用程序,并且不能不出错

Code

我真的不知道为什么当 player.drawInRect 导致错误时 bg.drawInRect 不会导致错误?问题是当我们改变坐标时图像不会绘制/重绘

Sep 16 22:13:16 imac-admin.lan Letalka_drawrect[804] : CGContextRestoreGState: invalid context 0x0. This is a serious error. This application, or a library it uses, is using an invalid context and is thereby contributing to an overall degradation of system stability and reliability. This notice is a courtesy: please fix this problem. It will become a fatal error in an upcoming update.

最佳答案

您需要在 drawRect 调用之外启动计时器; didMoveToSuperview可能是个好地方,但这取决于您要完成的目标。然后,在 timerRedraw 中,调用 setNeedsDisplay()触发重新绘制。

var timer: NSTimer?

override func didMoveToSuperview() {
// Stop the timer if it was already running
if timer != nil {
timer.invalidate()
timer = nil
}

// Only start the timer if the view is actually part of a view hierarchy
if superview != nil {
timer = NSTimer.scheduledTimerWithTimeInterval(interval, target: self, selector: "timerRedraw", userInfo: nil, repeats: true)
}
}

func timerRedraw() {
x += 5
y += 6
setNeedsDisplay()
}

我强烈推荐阅读 Apple 的 Drawing and Printing Guide for iOS ,它解释了开始在 iOS 中进行自定义绘图所需了解的一切。

关于ios - UIImage.DrawInRect 导致错误/通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25876879/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com