我有一些摇晃 UIViews 的代码,就像您编辑 iOS 主屏幕时一样。
我有以下两种方法来实现这种摆动效果:
- (void)wobble {
int amountInRadians = (self.tag % 2) == 0 ? 2.0 : -2.0;
containerView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(-amountInRadians));
[UIView animateWithDuration:0.10
delay:0.0
options:(UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse)
animations:^ {
containerView.transform = CGAffineTransformRotate(CGAffineTransformIdentity, RADIANS(amountInRadians));
}
completion:NULL
];
}
- (void)stopWobble {
[UIView animateWithDuration:0.01
delay:0.0
options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionCurveLinear)
animations:^ {
containerView.transform = CGAffineTransformIdentity;
}
completion:NULL
];
}
当我停止摆动时,我收到警告(多次):
-[UIApplication beginIgnoringInteractionEvents] 溢出。无视。
然后(多次,匹配数量的开始):
-[UIApplication endIgnoringInteractionEvents] 调用时不匹配 -beginIgnoringInteractionEvents。无视。
到底是怎么回事?如果我注释掉 stopWobble 动画,那很好,但我的动画自然不会停止。如果我在开始动画时删除“UIViewAnimationOptionAllowUserInteraction”选项,我会收到beginIgnoringInteractionEvents警告,但这也不好,因为我需要在这些视图摆动时与它们进行交互。
这种行为很好,所以我应该忽略这个吗?在我看来,我应该解决一些问题,只要我能找出导致它的原因。