我创建的自定义 View 由其容器进行动画处理 - 在我的 View 中,我使用其他动画(例如 UICOllectionView)更新部分 subview
我看到这是抛出错误
*** Assertion failure in -[UICollectionView _endItemAnimations
四处挖掘,我发现我的 View 附加了动画:
<GeneratorView: 0x15b45950; frame = (0 0; 320 199); animations = { position=<CABasicAnimation: 0x145540a0>; }; layer = <CALayer: 0x15b49410>>
所以现在在执行动画操作之前我检查:
NSArray *animationKeys = [self.layer animationKeys];
for (NSString *key in animationKeys) {
CAAnimation *animation = [self.layer animationForKey:key];
}
我看到返回了动画对象:
在这一点上,我想“等待”直到所有动画都完成,然后再更新自身。
我看到我可以将自己添加为 CAAnimation 委托(delegate)。
但这有点困惑且难以追踪。
是否有使用 UIView 方法的更简单的方法 - 更高级别?
最佳答案
您可以使用 UIView 方法在容器中做动画:
[UIView animateWithDuration: animations: completion:];
[UIView animateWithDuration: delay: options: animations: completion:];
您应该将属性添加到您的自定义 View :
@property BOOL isAnimating;
在容器中运行动画 block 并更改 View 的 isAnimating 属性。 此方法接受将在动画完成时触发的 block 。 示例:
[UIView animateWithDuration:1.0 animations:^{
//Your animation block
view1.isAnimating = YES;
view1.frame = CGRectMake(50.0f, 50.0f, 100.0f, 100.0f);
// etc.
}completion:^(BOOL finished){
view1.isAnimating = NO;
NSLog(@"Animation completed.");
}];
现在它是您的 View ,您可以查看该 View 是否具有动画效果:
if (self.isAnimating)
NSLog(@"view is animating");
关于ios - 如何知道 UIView 动画何时全部完成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21853601/