gpt4 book ai didi

ios - 更改 uiviewcontroller 时动画停止

转载 作者:行者123 更新时间:2023-11-30 12:10:38 24 4
gpt4 key购买 nike

我为第一个 View Controller 编写选取框文本,但更改 Controller 并返回第一个 View Controller 选取框文本不起作用。

第一个 Controller 代码:

@IBOutlet weak var marqueeText: UILabel!        

override func viewDidLoad() {

super.viewDidLoad()
UIView.animate(withDuration: 16.0, delay: 1, options: ([.curveLinear, .repeat]), animations: {() -> Void in
marqueeText.center = CGPoint(x: 0 -marqueeText.center.bounds.size.width / 2, y: text.center.y)
}, completion: { _ in })

}

最佳答案

请检查以下代码:

@IBOutlet weak var marqueeText: UILabel!

var marqueeTextPoint = CGPoint()
var stopAnim: Bool = false

override func viewDidLoad() {
super.viewDidLoad()
marqueeTextPoint = marqueeText.center
marquee(text: marqueeText)
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
self.marqueeText.center = self.marqueeTextPoint
marquee(text: marqueeText)
}

override func viewWillDisappear(_ animated: Bool) {
stopAnim = true
}

func marquee (text: UILabel) {
UIView.animate(withDuration: 16.0, delay: 1, options: ([.curveLinear, .repeat]), animations: {
text.center = CGPoint(x: 0 - text.bounds.size.width / 2, y: text.center.y)
}, completion: { _ in
if !(self.stopAnim) {
self.marquee(text: text)
} else {
text.layer.removeAllAnimations()
}
})
}

关于ios - 更改 uiviewcontroller 时动画停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46106450/

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