2014-02-18 121 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

相關問題