I am trying to have a guy move to the left, turn around and then move to the right. I know how to do this in Spritekit, which is using SKAction sequence. However, I am really having a hard time doing it in a app rather than a game. What I have now will result in the guy moving and turning at the same time:
我想让一个人向左移动,转身然后向右移动。我知道如何在使用SKAction序列的Spritekit中执行此操作。但是,我真的很难在应用程序而不是游戏中执行此操作。我现在所拥有的将导致这个家伙同时移动和转动:
UIView.animateWithDuration(5.0, delay: 0.0, options: [ .Repeat, .Autoreverse, .CurveEaseInOut], animations: {
self.guy.center.x -= 130
}, completion: nil)
//
UIView.animateWithDuration(5.0, delay: 5.0, options: [ .CurveEaseInOut, .Repeat, .Autoreverse ], animations: {
self.guy.transform = CGAffineTransformMakeScale(-1, 1)
}, completion:nil )
Thanks!
1 个解决方案
#1
0
You can use the completion handler if the first animation to fire the second animation.
如果第一个动画要触发第二个动画,则可以使用完成处理程序。
Put that into a function and fire this function with a timer to create a loop
将它放入函数中并使用计时器触发此函数以创建循环
UIView.animateWithDuration(5.0, delay: 0.0, options: [ .Repeat, .Autoreverse, .CurveEaseInOut], animations: {
self.guy.center.x -= 130
}, completion: {
UIView.animateWithDuration(5.0, delay: 0.0, options: [ .CurveEaseInOut, .Repeat, .Autoreverse ], animations: {
self.guy.transform = CGAffineTransformMakeScale(-1, 1)
}, completion:nil )
})
#1
0
You can use the completion handler if the first animation to fire the second animation.
如果第一个动画要触发第二个动画,则可以使用完成处理程序。
Put that into a function and fire this function with a timer to create a loop
将它放入函数中并使用计时器触发此函数以创建循环
UIView.animateWithDuration(5.0, delay: 0.0, options: [ .Repeat, .Autoreverse, .CurveEaseInOut], animations: {
self.guy.center.x -= 130
}, completion: {
UIView.animateWithDuration(5.0, delay: 0.0, options: [ .CurveEaseInOut, .Repeat, .Autoreverse ], animations: {
self.guy.transform = CGAffineTransformMakeScale(-1, 1)
}, completion:nil )
})