检查UIView是否正在进行动画。

5
我有两个动画正在运行:显示搜索栏和显示横幅。这两个动画都在调整同一个视图的大小,如果它们同时运行(它们是同时运行的),则最新的动画将取消调整大小。是否有任何方法可以检查UIView当前是否正在进行动画,并等待动画完成?
我相当确定我没有使用CAAnimations,因为Cocoa没有检测到这样的类。
这个动画是在接收到广告时运行的。不幸的是,这与ShowSearch同时运行。
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView {
    if (!hasloaded) {
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationCurve: UIViewAnimationCurveEaseInOut];
        [UIView setAnimationDuration: 1.0];

        [bannerView_ setFrame:CGRectMake(0, self.view.frame.size.height, bannerView_.frame.size.width, bannerView_.frame.size.height)];

        // move and grow
        [bannerView_ setFrame:CGRectMake(0, self.view.frame.size.height-50, bannerView_.frame.size.width, bannerView_.frame.size.height)];
        // set original position
        [UIT setFrame:CGRectMake(UIT.frame.origin.x, UIT.frame.origin.y, UIT.frame.size.width, UIT.frame.size.height)];

        // move and grow
        [UIT setFrame:CGRectMake(UIT.frame.origin.x, UIT.frame.origin.y, UIT.frame.size.width, UIT.frame.size.height-50)];

        [UIView commitAnimations];
        hasloaded = true;
    }
}

使用- (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)方法成功运行。 - Hedam
2个回答

2

不,更像是使用类似于 while(UIView.isAnimating == YES){ //WAIT } 的代码等待另一个动画完成。 - Hedam
那么您希望在动画运行时什么也不做,并在完成时开始做某些事情?为什么不使用完成块呢?我真的看不出有什么区别。 - omz
1
我之前不知道那个存在。 - Hedam

0

如果您在输入代码时选择它并按下control+K,您将保留格式并使其更美观。试试看。将代码粘贴到真正的非彩色格式环境中生成的文本墙。

Nick Weaver说:

UIView有一个图层(CALayer)。您可以向其发送animationKeys,这将为您提供标识附加到该图层的动画的键数组。我想,如果有任何条目,则正在运行动画。如果您想深入了解,请查看CALayer采用的CAMediaTiming协议。它对当前动画的一些更多信息。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接