【发布时间】:2019-12-03 11:08:41
【问题描述】:
我用一副纸牌创建了圆圈,用户可以旋转来选择一个。平移结束后,它会以漂亮的减速动画捕捉到指定的角度。将来会有某种迹象表明 45 度角的卡是选定的卡。
我想指出选择随着触觉反馈而改变,就像在UIPickerView 中一样。现在我正在尝试将触觉反馈添加到减速动画中。我的想法是制作反馈生成器并在动画中调用.selectionChanged() 的次数与跳过的卡片数量一样多。但现在我决定只是简单地调用它 3 次。不幸的是,我的任何想法都不起作用——即使创建一个单独的UIViewPropertyAnimator 也不起作用。我想我应该只将动画属性放在动画闭包中。动画师本身工作正常 - 减速动画工作。
animator.addAnimations {
UIView.animateKeyframes(withDuration: 5.0, delay: 0.0, options: [], animations: {
UIView.addKeyframe(withRelativeStartTime: 1.0/3.0, relativeDuration: 0.0, animations: {
self.selectionGenerator.selectionChanged()
})
UIView.addKeyframe(withRelativeStartTime: 2.0/3.0, relativeDuration: 0.0, animations: {
self.selectionGenerator.selectionChanged()
})
UIView.addKeyframe(withRelativeStartTime: 3.0/3.0, relativeDuration: 0.0, animations: {
self.selectionGenerator.selectionChanged()
})
})
}
animator.startAnimation()
如何模拟例如DatePicker的触觉反馈行为,在选择变化时振动?
【问题讨论】:
标签: ios swift iphone animation haptic-feedback