为什么我应该使用基于块的动画而不是开始/结束动画? [英] Why should I use the block-based animation rather than begin/end animation?

查看:63
本文介绍了为什么我应该使用基于块的动画而不是开始/结束动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如您所知,Apple鼓励我们使用一种新的方法,称为基于块的动画,以讨论iOS 4.0上的动画。

As you know, Apple encourages us to use a new method called block-based animation about animation over iOS 4.0.

我真的很想知道什么是基于块的动画比开始/结束样式动画更好。

   性能?

   并发?

   

I really wonder what block-based animation is better than begin/end style animation.
    performance?
    concurrency?
    coding efficiency and convenience?

推荐答案

我当时也想知道这一点。

I wondered about this too back then.

但是在使用像这样的基于块的动画之后:

But after using block based animations like this:

[UIView animateWithDuration:0.5 ... ^{
    // animated custom view vertically
} completion:^{
    [UIView animateWithDuration:0.5 ... ^{
        // animate the fade in alpha of buttons
    }];
}];

它以简短的方式提供了完成处理程序。您还可以将子动画块彼此嵌套。

It provides the completion handler in a short concise manner. You can also nest sub animation blocks within each other.

使用BeginAnimation / EndAnimation,我不记得要如何为完成处理程序进行回调,但是您通常会这样做

With BeginAnimation/EndAnimation, I don't recall exactly how to do a callback for completion handler, but you usually do something like:

//开始动画
//设置委托
//为每个beginAnimation创建委托回调函数

// begin animation // set delegate // create delegate callback function for each beginAnimation

现在想象一下,如果您想嵌套3或4级动画,例如复制CSS灯箱效果:

Now imagine if you wanted to nest 3 or 4 levels animation, such as as replicating the CSS Lightbox effect:

1)淡入灯箱容器

2)扩展宽度

3)扩展高度

4)淡入淡出

您必须处理一些非常杂乱的if-else条件。

You'd have to deal with some pretty messy if-else condition.

您的工作流程将如下:

beginAnimation完成后,它将向我的回调方法发送一条消息,向下滚动Xcode来找到回调委托方法,然后在回调方法中调用另一个UIView beginAnimation,向上滚动Xcode来查找下一个beginAnimation ...

"After this beginAnimation finish, it sends a message to my callback method, scrolls down Xcode to find the callback delegate method, then in the callback method it calls another UIView beginAnimation, scroll back up Xcode to find the next beginAnimation ... "

使用基于块的动画,每个过程都封装在一个块中,您可以将其嵌套在另一个块中。如果您确定要更改顺序,则显示的内容如下:

With block based animation, each process is encapsulated in a block which you can nest in another block. If you decided you want to change the order things appear such that:

1)淡入Lightbox容器

1) Fade in Lightbox container

2)这次在宽度之前扩大高度

2) Expand Height before Width this time

3)这次在高度之后扩大宽度

3) Expand Width after height this time

4)形式

使用beginAnimation方法,您将开始拔头发。

With the beginAnimation approach, you'll start pulling your hairs out.

希望有所帮助。

这篇关于为什么我应该使用基于块的动画而不是开始/结束动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆