gpt4 book ai didi

ios - UILabel 的滑动动画

转载 作者:行者123 更新时间:2023-11-29 05:40:32 26 4
gpt4 key购买 nike

我有这个函数可以循环数组并更改 2 个标签。我怎样才能使 UILabels 从右侧出现并离开左侧?

func updateLabels() {
self.myTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { (t) in
self.titleLabel.text = self.titleArray[self.counter]
self.textLabel.text = self.textArray[self.counter]
self.counter += 1
if self.counter == self.titleArray.count && self.counter == self.textArray.count {
self.counter = 0
}
}
}

最佳答案

UILabel从右向左移动。向文本标签添加适当的约束,如果您想从右到左获得动画,请将文本对齐设置为右

func updateLabels() {

self.myTimer = Timer.scheduledTimer(withTimeInterval: 2, repeats: true) { (t) in
self.titleLabel.text = self.titleArray[self.counter]
self.textLabel.text = self.textArray[self.counter]
DispatchQueue.main.async(execute: {
UIView.animate(withDuration: 5.0, delay: 1, options: ([.curveLinear, .repeat]), animations: {() -> Void in
self.textLabel.center = CGPoint(x:0 - self.textLabel.bounds.size.width/2, y:self.textLabel.center.y)
}, completion: nil)
})
self.counter += 1
if self.counter == self.titleArray.count && self.counter ==
self.textArray.count {
self.counter = 0
}
}
}

关于ios - UILabel 的滑动动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56600928/

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