我已将此动画代码添加到按下按钮时调用的函数的末尾,但是在动画发生时,它将忽略设置的目标选择器,直到动画完成。动画非常快,但是我希望用户能够快速按下它。
let transforms: CGAffineTransform = .identity
mirroredButton.transform = transforms
UIView.animate(withDuration: 0.05, animations: {
mirroredButton.transform = transforms.scaledBy(x: 0.75, y: 0.75)
},
completion: { _ in
UIView.animate(withDuration: 0.1) {
mirroredButton.transform = transforms.scaledBy(x: 1.0, y: 1.0)
}
})
更新:
使用答案,我更新了动画代码,如下所示。两个动画调用都需要选项。第二个有一个nil完成处理程序。
let transforms: CGAffineTransform = .identity
mirroredButton.transform = transforms
UIView.animate(withDuration: 0.05, delay: 0.0, options: .allowUserInteraction, animations: {
mirroredButton.transform = transforms.scaledBy(x: 0.75, y: 0.75)
},
completion: { _ in
UIView.animate(withDuration: 0.1, delay: 0.0, options: .allowUserInteraction, animations: {
mirroredButton.transform = transforms.scaledBy(x: 1.0, y: 1.0)
}, completion:nil)
})
答案 0 :(得分:1)
在视图的动画过程中禁用了用户交互。如果在动画播放期间用户应与视图交互至关重要,则可以传递选项TransactionTemplate txTemplate = new TransactionTemplate(platformTransactionManagerHere);
txTemplate.setPropagationBehavior(TransactionDefinition.PROPAGATION_REQUIRES_NEW);
txTemplate.execute(new TransactionCallback<Object>() {
public Object doInTransaction(TransactionStatus status) {
// do stuff
}
});
,如下所示:
.allowUserInteraction