Scripts Animation blocks iOS

I am trying to animate a series of full-screen images. Each image will be animated differently. I would like to save these animations somewhere in the database or in a plist or something else, I just do not want them to be hardcoded. The animation will be very simple, the objects inside the image will tremble or bounce or whatever you have. I'm going to animate objects using blocks, and ideally I would like individual blocks to be stored in a data store. I would like to avoid using a separate scripting language or something similar.

What is my best course of action?

+3
source share
2 answers

, , plist, - :

<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>

, - :

- (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... */
    }
}
+2

, , . , .

-(void)jiggle:(UIView *)image {
    [UIView animateWithDuration:.1
                          delay:0
                        options:UIViewAnimationOptionLayoutSubviews
                     animations:^{
                         image.transform = CGAffineTransformMakeRotation(-5 * M_PI / 180);
                     }
                     completion:^(BOOL finished){
                         [UIView animateWithDuration:.1
                                               delay:0
                                             options:UIViewAnimationOptionLayoutSubviews
                                          animations:^{
                                              image.transform = CGAffineTransformMakeRotation(5 * M_PI / 180);
                                          }
                                          completion:^(BOOL finished){
                                              [UIView animateWithDuration:.1
                                                                    delay:0
                                                                  options:UIViewAnimationOptionLayoutSubviews
                                                               animations:^{
                                                                   image.transform = CGAffineTransformMakeRotation(0 * M_PI / 180);
                                                               }
                                                               completion:nil
                                               ];
                                          }
                          ];
                     }
     ];
}
0

All Articles