ios - 点击播放按钮闪烁停止

标签 ios swift uiview uibutton

我有一个游戏,对于主页,我希望“点击播放”按钮淡入淡出。这是我的代码:

import UIKit

class HomePageViewController: UIViewController {

@IBOutlet weak var highscoreLabel: UILabel!
@IBOutlet weak var taptoplay: UIButton!

override func viewDidLoad() {
    super.viewDidLoad()

    flashing(buttonName: taptoplay)

    let highscore = UserDefaults.standard.integer(forKey: "highscore")
    highscoreLabel.text = "Highscore: \(highscore)"
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

func flashing(buttonName:UIButton) {
    UIView.animate(withDuration: 1, delay: 0, options: UIViewAnimationOptions.autoreverse, animations: {
        buttonName.alpha = 1
        buttonName.alpha = 0
    }, completion: nil)

}

}

我的问题是文本完全按照我想要的方式闪烁了大约两次,但随后就消失了,我什至无法点击按钮。事实上,即使按钮正确闪烁,我也无法点击它。

在我添加此代码之前,该按钮工作正常,并且仍然全部正确链接。感谢您的帮助。

最佳答案

当您为按钮设置动画时,您对它所做的最后一件事是将其 alpha 设置为 0。不知何故,您需要在按钮完成动画后将 alpha 设置回 1,或者更改顺序,并设置alpha 首先变为 0。

编辑:此外,用户交互的默认设置为零,因此您需要添加另一个选项:allowUserInteraction

希望这对您有所帮助。

关于ios - 点击播放按钮闪烁停止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47442136/

相关文章:

iphone - iPhone OS 4.0 中基于 block 的动画方法是什么?

ios - iOS Objective-C,释放对象后具有相同的内存地址

swift - 等待 promise 返回

swift - Swift 中的多级泛型类型约束

swift - 如何在 Swift 中正确设置字符串格式以填充标签

iphone - 从 ViewController 中移除 UIView

ios - 从本地文件系统检索视频数据

带有 Cedar 的 iOS 测试 Controller

ios - 跟踪应用程序的运行时间 iOS

ios - 第二个 bug 的 CLLocation 时间戳分数?