【发布时间】:2016-09-19 16:33:37
【问题描述】:
我在使用 addsubview 创建按钮时遇到问题。即使我增加循环中动画的延迟,它们也会立即出现。我会感谢任何可以提供帮助的人。
func createButton () {
var setx = 50
var sety = 100
var delay = 0.4
var wordsInCharacters = [String]()
for letter in "RAILROAD".characters{
wordsInCharacters.append("\(letter)")
}
while wordsInCharacters.count > 0 {
let randomIndex = Int(arc4random_uniform(UInt32(wordsInCharacters.count)))
// Creating the buttons
let button = SpringButton()
button.frame = CGRect(x: setx, y: sety, width: 64, height: 64)
button.setTitle( "\(wordsInCharacters[randomIndex])", for: .normal)
button.setTitleColor(UIColor.white, for: .normal)
button.backgroundColor = UIColor.gray
button.titleLabel?.font = UIFont(name: "HelveticaNeue", size: 30)
// Add animation
UIView.animate(withDuration: 1, delay: delay, options: .curveEaseInOut, animations: {
self.view.addSubview(button)
}, completion: nil)
if setx <= 200 {
setx += 100
}
else{
setx = 50
sety += 100
}
wordsInCharacters.remove(at: randomIndex)
delay += 0.2
}
}
【问题讨论】:
-
你想对按钮做什么样的动画?褪色?
-
问题是“addSubview”不是一个神奇的动画。只有可动画的视图属性可以在
UIView.animate动画函数中进行动画处理。添加可动画的子视图的概念没有任何意义。它甚至不是可见的属性!
标签: swift addsubview