2011-05-24 147 views
1

我正面临动画问题。在动画视图时动画UIButton

所以现在在我的应用程序中,我有一个关闭按钮的子视图。当按下关闭按钮时,会出现一个卷曲的动画,显示前一个视图。这是正常工作。我执行卷曲向下传递一个通知NSNotificationCenter这样[[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:self];

关闭动画现在我想的动画应用到关闭按钮本身,这样,当我按下关闭按钮,它会执行动画以及卷曲下来的动画会发生。所以,我的方式做到这一点是通过下面的代码

[UIView transitionWithView:self.view.superview duration:1 
         options:UIViewAnimationOptionCurveEaseIn 
        animations:^ { 
         closeButton.frame = CGRectMake(500, 15, 100, 40); } 
        completion:nil]; 

,以前的closeButton.frame过的(580,15,100,40)的值,因此动画会是这样的形象是从直接从向左移动580到500.

因此,当我运行代码时会发生什么情况,当我按下关闭按钮时,关闭按钮动画不会发生,但会发生向下卷动画。因此,为了进行测试,当我注释了我发布通知的代码时,关闭按钮动画完美运行,但不会发生向下卷动画,也不会出现前一个视图(因为我不发送通知,导致视图关)。

我想知道这里出了什么问题,为什么它不允许同时发生2个动画。

回答

0

这是我如何解决它......

我使用块使用嵌套的动画,我包括为卷曲的关闭按钮动画完成部分下降近观代码...

[UIView transitionWithView:self.view.superview duration:1 
         options:UIViewAnimationOptionCurveEaseIn 
        animations:^ { 
         popContents.closeButton.frame = CGRectMake(500, 15, 100, 40); } 
        completion:^(BOOL finished){ 
         [UIView transitionWithView:self.view.superview duration:1 
              options:UIViewAnimationOptionTransitionCurlDown 
             animations:^ { 
              popContents = nil; 
              [popContents.view removeFromSuperview]; 
              [ovController.view removeFromSuperview]; 
              ovController = nil; } 
             completion:nil]; 
        }];