2014-02-25 97 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