2014-02-25 91 views
1

在我的iOS應用程序中,我試圖同時執行2個動畫。但是,下面的代碼不會做我想要的。它取消了第一個動畫,並且只執行了第二個(通知中的一個)。至於第一個就是在1秒後達到最終結果。一個UIView動畫取消了iOS中的另一個動畫

dispatch_async(dispatch_get_main_queue(),^{ 
    CGRect tempRect = CGRectMake(0, self.view.frame.size.height, toolbar.frame.size.width, toolbar.frame.size.height); 
    [UIView animateWithDuration: 1.0f 
    animations:^{ 
     toolbar.frame = tempRect; 
    } 
    completion:^(BOOL finished) { 
     [toolbar setHidden: YES]; 
     isPlayerToolbarActive = NO; 
    }]; 
}); 

[ 
    [NSNotificationCenter defaultCenter] postNotificationName: @"animateSidePanels" 
    object: @"removingPlayerToolbar"]; 

// notification is sent here 

- 
(void) animateSidePanels: (NSNotification *) notification { 
    if ([notification.object isEqualToString: @"removingPlayerToolbar"]) { 
     [self.interactionsViewController performExtendAnimation: self.interactionsViewController.view.frame.size.height + 44 
     withDuration: 1.0f 
     completion:^(BOOL finished) { 

     }]; 
    } 
} 

-(void)performExtendAnimation:(CGFloat)newHeight withDuration:(CGFloat)duration completion:(void (^)(BOOL finished))completion 
{ 
    [UIView animateWithDuration:duration animations:^{ 
    CGRect newFrame = CGRectMake(self.view.frame.origin.x, 
           self.view.frame.origin.y, 
           self.view.frame.size.width, 
           newHeight); 
    self.view.frame = newFrame; 

}completion: completion]; 

} 任何形式的幫助,高度讚賞!

+0

「工具欄」和「self.interactionsViewController.view'有什麼關係?我的猜測是,工具欄是交互控制器視圖的子視圖。是對的嗎? – Tricertops

回答

2

嘗試使用UIViewanimateWithDuration:delay:options:animations:completion:方法並在選項中提供UIViewAnimationOptionBeginFromCurrentStateUIViewAnimationOptionAllowAnimatedContent

+0

這可能也有幫助,但我們沒有在'performExtendAnimation:'裏面看到......所以我們不知道什麼是動畫。 – Tricertops

+0

只是試過了......它沒有解決問題:( –

1

要動畫interactionViewController的延伸動畫,使用方法:

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

與選項UIViewAnimationOptionAllowAnimatedContent