Scripting Animation blocks iOS

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?

  • iOS: ' It appears that “Crashlytics” is not a valid Fabric Kit
  • How can I prevent iPhone (including iOS 7) from going to sleep in HTML or JS?
  • How do I perform a fast pixellation filter on an image?
  • Any way to install app to iPhone 4 with Xcode 8 beta?
  • iOS MapKit dragged annotations (MKAnnotationView) no longer pan with map
  • How to receive NSNotifications from UIWebView embedded YouTube video playback
  • 2 Solutions Collect From Internet About “Scripting Animation blocks iOS”

    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>
    

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

    It’s not clear to me what benefit you might get from storing the animations in a data store, if that were possible. If you just don’t want to repeat the animation code, you can put it in a method and pass the view(s) to the method.

    -(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
                                                   ];
                                              }
                              ];
                         }
         ];
    }