Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/115.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/16.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
如何使“animateWithDuration”每次调用时都从同一点开始,iOS,Swift_Ios_Swift - Fatal编程技术网

如何使“animateWithDuration”每次调用时都从同一点开始,iOS,Swift

如何使“animateWithDuration”每次调用时都从同一点开始,iOS,Swift,ios,swift,Ios,Swift,我不确定我是否遗漏了什么,或者只是没有正确计算dxdy偏移量,但我有一个UILabel位于x:0 y:0,并且正在使用animateWithDuration函数向带有一点动画的视图添加UILabel 但是,每次调用它时,它只是从动画最后停止的位置移动另一个dy:100 这是我的密码: //UILabel variable - Global variable if you must know. var informationView: UILabel = UILabel(frame: CGRect

我不确定我是否遗漏了什么,或者只是没有正确计算
dx
dy
偏移量,但我有一个UILabel位于
x:0 y:0
,并且正在使用
animateWithDuration
函数向带有一点动画的视图添加UILabel

但是,每次调用它时,它只是从动画最后停止的位置移动另一个
dy:100

这是我的密码:

//UILabel variable - Global variable if you must know.
var informationView: UILabel = UILabel(frame: CGRect(x: 0, y: 0, width: 400, height: 400))

//Function to present UILabel with animation.
func animate(){
    UILabel.animateWithDuration(0.5,
            delay: 0.0,
            usingSpringWithDamping: 0.3,
            initialSpringVelocity: 3.0,
            options: UIViewAnimationOptions.CurveEaseInOut,
            animations: ({
                self.informationView.frame.offset(dx: 0, dy: 100)}),
            completion: nil)
}

任何帮助都将不胜感激。

在再次设置动画之前,您必须将帧的原点重置为(0,0),否则您只需将另一个偏移量100添加到当前原点的y值即可。你可以用另一个动画来做,或者直接将它设置为跳回。非常好,谢谢。真不敢相信我竟然没有想到要这么做。