【发布时间】:2021-10-23 23:28:15
【问题描述】:
玩 UIViewPropertyAnimator,我遇到了一个奇怪的问题。
这里,
let animator = UIViewPropertyAnimator(duration: 1, curve: .linear)
animator.addAnimations(someAnimationBlock)
animator.addCompletion{ position in
switch position
{
case .current:
print("is current")
case .start:
print("is start")
case .end:
print("is end")
print(self.animator.state == .active)
print(self.animator.state == .inactive)
print(self.animator.state == .none)
print(self.animator.state == .stopped)
}
}
animator.startAnimation()
这段代码运行后,这会到达.end position 的完成块,但对于动画师来说,所有状态都是错误的。为什么会这样?
据我所知,随着动画自然完成,它应该处于.inactive 状态。
P.s 我在完成块中试图触发 animator.startAnimation() 并且完成块不再被调用。我知道startAnimation() 仅在animator's 状态为.inactive 时有效。所以在这里我测试了,我没有收到任何状态值,需要帮助!
【问题讨论】:
-
如果你在
debugPrint(self.animator.state).end中得到什么? -
它将打印'__C.UIViewAnimatingState'。如果我 debugPrint(self.animator.state.rawValue) 它打印'5',根据苹果文档 UIViewAnimatingState 是一个符合 int 的枚举,并具有三种情况,即活动、非活动和停止,其值分别为 0,1 和 2。我不明白为什么这个打印 5 不应该是这样。
标签: ios swift core-animation