1

我在动画中遇到问题。

所以现在在我的应用程序中,我有一个带有关闭按钮的子视图。当按下关闭按钮时,会出现一个向下卷曲的动画,显示上一个视图。那工作正常。我通过像这样向 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 个动画。

4

1 回答 1

0

这是我解决它的方法...

我使用了使用块的嵌套动画,其中我在关闭按钮动画的完成部分中包含了 curl down 关闭视图的代码......

[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];
                    }];
于 2011-05-25T14:54:52.107 回答