Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/109.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何在应用程序中创建动作序列,如在spritekit游戏中?_Ios_Swift_Animation - Fatal编程技术网

Ios 如何在应用程序中创建动作序列,如在spritekit游戏中?

Ios 如何在应用程序中创建动作序列,如在spritekit游戏中?,ios,swift,animation,Ios,Swift,Animation,我试着让一个人向左移动,转过身,然后向右移动。我知道如何在Spritekit中实现这一点,它使用SKAction序列。然而,我真的很难在应用程序而不是游戏中做到这一点。我现在所做的将导致家伙同时移动和转向: UIView.animateWithDuration(5.0, delay: 0.0, options: [ .Repeat, .Autoreverse, .CurveEaseInOut], animations: { self.guy.center.x -= 130

我试着让一个人向左移动,转过身,然后向右移动。我知道如何在Spritekit中实现这一点,它使用SKAction序列。然而,我真的很难在应用程序而不是游戏中做到这一点。我现在所做的将导致家伙同时移动和转向:

    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 )

谢谢

如果第一个动画触发第二个动画,则可以使用完成处理程序

将其放入函数中,并使用计时器启动此函数以创建循环

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 )
})