脚本动画块的iOS [英] Scripting Animation blocks iOS

查看:127
本文介绍了脚本动画块的iOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图动画系列全屏幕图像。每个图像将用不同的方式进行动画处理。我想保存这些动画的地方无论是在数据库或plist中或什么的,我只是不想让他们很难codeD。该动画将是非常简单的,图像中的物体会摇晃或反弹,或你有什么。我将动画用块中的对象和理想我想各个块被存储在数据存储中。我想避免使用单独的脚本语言或类似的东西。

I'm trying to animate a series of full screen images. Each image will be animated in a different way. I'd like to store these animations somewhere either in a database or plist or whatever, I just don't want to have them hard coded. The animations will be very simple, objects within the image will jiggle or bounce or what have you. I'm going to animate the objects using blocks and ideally i'd like the individual blocks to be stored in the data store. I'd like to avoid using a separate scripting language or something like that.

什么是我最好的行动方针?

What is my best course of action?

推荐答案

如果你想在他们的存储,例如,一个plist中,你可以做这样的事情:

If you want to store them in, for example, a plist, you can do something like this:

<plist>
<array>
    <dict>
        <key>filename</key>
        <string>first.jpg</string>
        <key>animation</key>
        <string>bounce</string>
        <key>duration</key>
        <real>0.5</real>
    </dict>
    <dict>
        <key>filename</key>
        <string>second.jpg</string>
        <key>animation</key>
        <string>easeinout</string>
        <key>duration</key>
        <real>1.0</real>
    </dict>
    <!-- et cetera -->
</array>
</plist>

然后,你可以通过编写类似下面的code段去code此为实际的动画:

Then you can decode this into actual animations by writing something like the following code snippet:

- (void)loadAnimations
{
    NSArray *animations = [NSArray arrayWithContentsOfFile:@"/Users/H2CO3/animations.plist"];
    for (NSDictionary *animation in animations)
    {
        UIImage *img = [UIImage imageNamed:[animation objectForKey:@"filename"]];
        NSString *animationType = [animation objectForKey:@"animation"];
        float duration = [(NSNumber *)[animation objectForKey:@"duration"] floatValue];

        if ([animationType isEqualToString:@"bounce"])
        {
            /* animation block 1 */
        }
        else if ([animationType isEqualToString:@"easeinout"])
        {
            /* animation block 2 */
        }
        /* Et cetera... */
    }
}

这篇关于脚本动画块的iOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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