2014-02-18 65 views
3

我创建是由它的容器的动画自定义视图 - 与其他动画子视图的我的看法我更新的部分(例如一个UICOllectionView)如何知道什么时候UIView的动画已经全部完成

我看到这个是抛出错误

*** Assertion failure in -[UICollectionView _endItemAnimations 

周围挖我看到我的观点有连接到它的动画:

<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委托。

但是这有点乱,很难追踪。

有更简单的方法使用UIView方法 - 更高的水平?

+0

你使用哪种方法来制作动画的看法? – Greg

+0

我不是动画 - 容器是 - 我想知道什么时候我的视图(自我)不是动画 - 即如果(自己动画){等待它停止动画}现在做一些动画; –

+0

我发布的问题中的动画是由其他对象执行的 - 在视图中 - 现在视图想要在这些动画完成时为其子视图设置动画效果 –

回答

0

我思你可以在你的是:

@interface UIView(UIViewAnimationWithBlocks) 

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); 

希望这将有助于

3

您可以使用UIView的方法做动画的容器:

[UIView animateWithDuration: animations: completion:]; 
[UIView animateWithDuration: delay: options: animations: completion:]; 

你应该添加属性您的自定义视图:

@property BOOL isAnimating; 

在容器中运行动画块并更改视图isAnimating属性。 该方法接受在动画完成时将被触发的块。 例子:

[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."); 
    }]; 

现在你的观点,你可以看到,如果视图动画:

if (self.isAnimating) 
    NSLog(@"view is animating"); 
+0

@Avner Barr查看我编辑的帖子。 – Greg

相关问题