【发布时间】:2014-08-07 17:06:38
【问题描述】:
我正在使用 Xcode 6 Beta 5 和 Swift 制作 iPhone 游戏。目前看起来像这样:
用户必须用手指在向上移动的块之间移动。为此,我为每个块创建了 UIView,并使用算法生成随机路径。我首先使用 animateWithDuration 向上移动块,但是当我尝试添加用户触摸块时的检测时出现了复杂情况。
我现在正在尝试使用 NSTimer 来制作动画:
var shiftBlockTimer = NSTimer.scheduledTimerWithTimeInterval(0.01, target: self, selector: Selector("shiftBlocks"), userInfo: nil, repeats: true)
func shiftBlocks() {
for leftBlock in leftBlocks {
leftBlock.frame.origin.y -= 70
}
for rightBlock in rightBlocks {
rightBlock.frame.origin.y -= 70
}
}
这确实有效,但是运动是跳跃的,而不是我希望的平滑运动,并且在我使用 animateWithDuration 时也有。
有什么方法可以让这个运动变得更平滑,而不增加迭代次数? (这会降低我的应用速度)
【问题讨论】: