-1

UIViewPropertyAnimator用来控制多个动画的进度。我有一个 UIView 子类的二维数组。我想一次显示每个索引处的所有元素。出于某种原因,编译器不允许我使用addAnimations(_:delayFactor:)方法延迟添加新动画。有人可以告诉我我在这里做错了什么吗?

// I'm creating a new viewAnimator without any animations. No problems here
        self.viewAnimator = UIViewPropertyAnimator(duration: self.frameDelay * Double(self.spillBubbles.count),
                                                   curve: .easeIn,
                                                   animations: {})


        for (index, views) in self.spillBubbles.enumerated() {

            views.forEach({ self.simulationView.addSubview($0) })

            // That's where the compiler error occurs 
            self.viewAnimator!.addAnimations({
                views.forEach({ self.simulationView.addSubview($0) })
            }, delayFactor: Double(index) / Double(self.spillBubbles.count))

        }

当我尝试调用 .addAnimations 时,我收到以下消息: Cannot invoke 'addAnimations' with an argument list of type '(() -> (), delayFactor: Double)'

我在这里做错了什么?在初始化程序中调用的相同闭包UIViewPropertyAnimator可以正常工作。

4

1 回答 1

1

错误信息非常清楚。如果不够清楚,只需查看文档:

https://developer.apple.com/documentation/uikit/uiviewpropertyanimator/1648370-addanimations

delayFactor需要是 CGFloat,而不是 Double 。

于 2019-05-29T22:12:23.820 回答