【发布时间】:2017-09-24 14:43:16
【问题描述】:
我在另一个函数中以编程方式创建了 14 个按钮,我向它们添加了目标并让它们为每个按钮设置动画,当我按下任何按钮时我都有目标转到目标,我的问题 如何返回使用 UIView.Animate ??
就像这个 Gif 一样:
代码:
var tileArrayXAxis: [Int] = [] // X-Axis of the my 14 buttons
var tileArrayYAxis: [Int] = [] // Y-Axis of the my 14 buttons
var tileArrayWidth: [Int] = [] // Width of the my 14 buttons
var tileArrayHeight: [Int] = [] // Heigh of the my 14 buttons
var targetArrayXAxis: [Int] = [] // X-Axis of the target
var targetArrayYAxis: [Int] = [] // Y-Axis of the target
var targetArrayWidth: [Int] = [] // Width of the target
var targetArrayHeight: [Int] = [] // Heigh of the target
var i : Int = 0
func moveButton(sender: UIButton) {
var xS = Int()
var yS = Int()
var widthS = Int()
var heightS = Int()
if i < targetArrayXAxis.count && i < targetArrayYAxis.count && i < targetArrayWidth.count && i < targetArrayHeight.count {
xS = targetArrayXAxis[i]
yS = targetArrayYAxis[i]
widthS = targetArrayWidth[i]
heightS = targetArrayHeight[i]
yS -= widthS
let startS = CGPoint(x: xS, y: yS)
let sizeS = CGSize(width: widthS, height: heightS)
sender.frame = CGRect(x: startS.x, y: startS.y, width: sizeS.width, height: sizeS.width)
}
UIView.animate(withDuration: 2, delay: 0, usingSpringWithDamping: 0.2, initialSpringVelocity: 6, options: .allowUserInteraction, animations: { [weak self] in
sender.transform = .identity
self?.i += 1
})
}
【问题讨论】:
-
sender.transform = .identity 不要移回原来的位置?
-
否@Arrabidas92
标签: ios swift uibutton uiviewanimation