【发布时间】:2015-02-23 23:12:42
【问题描述】:
在 ViewController.Swift 中,我设法让一个盒子从一个点到另一个点进行动画处理。我认为循环这个很容易,所以盒子会动画到一个点,然后动画回到它的原始位置,然后再次循环。我设法将对象移动到一个位置并在“完成”中再次将其移回,但这不会使 i 循环。如何实现?
我认为这可能可行,但老实说我不知道:
let boxmoves = [CGRect(x: 120, y: 220, width: 100, height: 100), CGRect(x: 120, y: 120, width: 100, height: 100)]
for boxmove in boxmoves {
coloredSquare.frame = boxmove
}
如何根据设备宽度将其居中(我假设涉及一些数学运算?)?
我的代码:
let coloredSquare = UIView()
coloredSquare.backgroundColor = UIColor.blueColor()
coloredSquare.frame = CGRect(x: 120, y: 120, width: 100, height: 100)
self.view.addSubview(coloredSquare)
// found repeate but this will not animate as I want.
//UIView.animateWithDuration(2.0, delay: 0.2, options: UIViewAnimationOptions.Repeat, animations: {
UIView.animateWithDuration(2.0, animations: {
coloredSquare.frame = CGRect(x: 120, y: 220, width: 100, height: 100)
}, completion: { finished in
UIView.animateWithDuration(2.0, animations: {
coloredSquare.frame = CGRect(x: 120, y: 120, width: 100, height: 100)
})
})
【问题讨论】:
标签: ios swift uikit core-animation uiviewanimation