我有一个 UILabel
,每次它接触时,它都会用 CGAffineTransformMakeScale
和动画进行缩放,然后用动画恢复到真实大小。现在,如果它在最后一个动画结束之前触及,它会缩放缩放对象而不是主要对象的实际大小,因此它会缩放得比它应该缩放的更多。如何防止这个问题?我想在最后一次缩放结束缩放对象的主要大小之前进行第二次触摸。
这是我的代码:
(void)MyLabelTouched
{
[UIView animateWithDuration:.15 animations:^{
MyLabel.transform = CGAffineTransformMakeScale(1.5,1.5);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.15 animations:^{
MyLabel.transform = CGAffineTransformIdentity;
}];
}];
}
最佳答案
试试这个
(void)MyLabelTouched
{
if(animRunning){return;}
animRunning = YES;
[ MyLabel.layer removeAllAnimations];
MyLabel.transform = CGAffineTransformIdentity;
[UIView animateWithDuration:.15 animations:^{
MyLabel.transform = CGAffineTransformMakeScale(1.5,1.5);
} completion:^(BOOL finished) {
[UIView animateWithDuration:.15 animations:^{
MyLabel.transform = CGAffineTransformIdentity;
animRunning = NO;
}];
}];
}
关于ios - 如何在 Objective-C 中同时防止对象上的 2 个动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48784978/