在动画视图时动画UIButton

时间:2011-05-24 19:22:38

标签: uiview uibutton ipad nsnotificationcenter uianimation

我在动画方面遇到了问题。

所以现在在我的应用程序中,我有一个子视图,它有一个关闭按钮。按下关闭按钮时,会出现一个卷曲动画,显示上一个视图。这是正常的。我通过将通知传递给NSNotificationCenter来执行curl down关闭动画,如[[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个动画。

1 个答案:

答案 0 :(得分: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];
                    }];