Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/95.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 如何从停止点恢复动画?_Ios_Swift_Animation_Core Animation - Fatal编程技术网

Ios 如何从停止点恢复动画?

Ios 如何从停止点恢复动画?,ios,swift,animation,core-animation,Ios,Swift,Animation,Core Animation,我有ViewController()和Circle.swift 在我的Circle.swift中,我有所有的动画代码,从ViewController我只调用它 因此,在Circle文件中,我有: func commonSetup() { ... fillingLayer.strokeStart = start anim.fromValue = start anim.toValue = end fillingLayer.strokeEnd = end

我有
ViewController()
Circle.swift

在我的
Circle.swift
中,我有所有的动画代码,从
ViewController
我只调用它

因此,在Circle文件中,我有:

func commonSetup() {
    ...

    fillingLayer.strokeStart = start
    anim.fromValue = start
    anim.toValue = end
    fillingLayer.strokeEnd = end

    fillingLayer.addAnimation(anim, forKey: "circleAnim")
}
其中,我在
类圆上方设置
start=0.0
end=0.55
:UIView{

在我的
ViewController
中,我有一个按钮,点击它我调用:

func pressed() {
    start = 0.55
    end = 0.9

    Circle().commonSetup()
}
但它不工作。我的动画无法恢复。我如何修复它?我想首先从0加载到0.55,然后单击按钮-从0.55加载到0.9


我在代码中看不到的内容?

您不应该经常更改
的值,即从value
更改为value
strokeStart

func commonSetup() {
  ...

  fillingLayer.strokeStart = 0;
  anim.fromValue = START_VALUE //value expressed in points
  anim.toValue = END_VALUE //value expressed in points
  fillingLayer.strokeEnd = end

  fillingLayer.addAnimation(anim, forKey: "circleAnim")
}

您应该设置
fromValue
toValue
strokeStart
属性的值,并且不要更改它们。您只能通过更改
strokeEnd
属性来控制动画。

问题是,当您说
circle().commonSetup()时,您正在创建一个新的circle实例
您需要在之前创建的circle实例上调用
commonSetup

所以看起来可能更像这样。在视图控制器中,有一个圆的变量

let progressCircle = Circle()
然后,在按下的功能中:

func pressed() {
    start = 0.55
    end = 0.9
    progressCircle.commonSetup()
}
如果希望将其用作类函数而不是实例函数(对于类似的情况,这可能是不正确的),则需要使用
class
关键字定义
commonSetup
函数,如下所示:

class func commonSetup() {
    //code
}
然后,您可以像这样使用它:
Circle.commonSetup()
。请注意
圆圈上缺少括号。
。这是因为您正在运行一个类函数,而不是初始化该类的新实例。但是……在您的情况下,将其作为类函数会很奇怪,因为您的函数实际上是在处理实例,而不是类级别的操作


我通常也习惯于在动画中使用适当的关键点。因此,你会说:
fillingLayer.addAnimation(anim,forKey:“strokeEnd”)

为笔划设置动画时,起始值和结束值是0.0-1.0,而不是点。