gpt4 book ai didi

iOS在动画过程中显示标签或图像位置

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

我正在尝试使用

UIView.animateWithDuration()

改变标签或图像的位置。这非常简单。但是我还需要在动画期间在屏幕中显示标签的 y 位置。所以我可以看到在动画过程中 y 位置是如何变化的。我该如何实现?

最佳答案

您可以从其presentationLayer 获取移动 View 的框架。您需要设置一个 NSTimer 以在您想要的任何重复间隔内获取该值。

class ViewController: UIViewController {

let block = UIView(frame: CGRect(x: 20, y: 100, width: 80, height: 80))

override func viewDidAppear(animated: Bool) {

super.viewDidAppear(animated)
block.backgroundColor = UIColor.redColor()
self.view.addSubview(block)
let timer = NSTimer.scheduledTimerWithTimeInterval(0.2, target: self, selector: "handleTimer", userInfo: nil, repeats: true)
UIView.animateWithDuration(5.0, animations: { () -> Void in
self.block.frame = CGRect(x: 300, y: 400, width: 80, height: 80)
}) { (finished) -> Void in
timer.invalidate()
}
}

func handleTimer() {
println(block.layer.presentationLayer().frame.origin.y)
}
}

关于iOS在动画过程中显示标签或图像位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29265920/

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