gpt4 book ai didi

ios - 无法在 Swift 中使用时间延迟为 UIImage 设置动画

转载 作者:行者123 更新时间:2023-11-28 10:45:16 24 4
gpt4 key购买 nike

我试图在 3 秒后为 UIImage 的 alpha 设置动画。默认情况下,alpha 设置为 0,3 秒后,alpha 应更改为 1,从而向用户显示图像。我为动画编写的代码确实将 alpha 设置为 0,但我无法在 3 秒后将 alpha 更改为 1。我是 swift 的新手,不确定我哪里出了问题。这是我的代码。

import UIKit

class WelcomeOneViewController: UIViewController {

@IBOutlet weak var swipeImageView: UIImageView!

override func viewDidLoad() {
super.viewDidLoad()
swipeImageView.alpha = 0
}

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
displaySwipeView()
}

func displaySwipeView() {
UIView.animate(withDuration: 1.0, delay: 3.0, options: .beginFromCurrentState, animations: {

DispatchQueue.main.async { [weak self] in
self?.swipeImageView.alpha = 1
}

}, completion: nil)
}

}

最佳答案

用这段代码试试:

import UIKit

class WelcomeOneViewController: UIViewController {

@IBOutlet weak var swipeImageView: UIImageView!

override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
swipeImageView.alpha = 0
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
displaySwipeView()
}

func displaySwipeView() {
swipeImageView.alpha = 0
UIView.animate(withDuration: 1.0, delay: 3.0, options: [], animations: {
self.swipeImageView.alpha = 1
}, completion: nil)
}

}

关于ios - 无法在 Swift 中使用时间延迟为 UIImage 设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48768247/

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