Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

Nested Animations

Hey guys,

I may be a tad naïve in asking this, but what is the problem with having nested animations? I've noticed that this can create some bugs when run in
the simulator, such as animations locking up the app. However, I have been unable to repeat these on the actual iPad itself…

When run in the simulator I get a range of messages such as:
[DEBUG] ignoring new layout while animating..
[DEBUG] animated called and we're not ready

and even

[DEBUG] animation guard triggered, we exceeded the timeout on waiting for view to become ready

I've come from a background of working with flash (a program which I understand breeds naïve/unexperienced developers)… I understand that Titanium isn't exactly optimised for doing a large amount of graphic/animation work, but so far I have found it to perform an AWFUL lot faster than the Flash Packager for iPhone. My project is basically just a childrens book with some basic animations of the characters moving. E.g. an arm rotating e.t.c

— asked December 7th 2010 by Bentley O'Kane-Chase
  • animation
  • freeze
  • iphone
  • mobile
3 Comments
  • Same problem here ! :-(

    — commented December 18th 2010 by Hansjuerg Wuethrich
  • Have you found a solution ? because i still have the same Problem since 2 months!

    "ignoring new layout while animating in layout Child.."

    so the next button click will not work, or only from time to time. (Timer Problem?!)

    — commented January 25th 2011 by Hansjuerg Wuethrich
  • The problem with nested animations is even worse on Android. Isn't there an "fx queue" module out there somewhere, like in jQuery?

    — commented May 16th 2013 by remko posthuma

6 Answers

  • Accepted Answer

    Views still have background work to complete upon creation before you animate them. Unfortunately you have to wait till they're finished and I know of no callback that lets you know when they finish.

    — answered March 22nd 2011 by Palmer Truelson
    permalink
    2 Comments
    • If you're using the latest SDK, you could listen for the 'postlayout' event on the view, then perform the animation. That seems to have stopped the warnings from appearing in the case of my app. Be sure to remove the event listener after the animation otherwise it may get triggered multiple times.

      — commented September 4th 2012 by Michael Aldridge
    • careful using the postlayout event when using animations - if you are changing anything in the view that would affect the layout of that view (screen position for example) you'll pop yourself into an infinite loop.

      — commented November 19th 2012 by Bert Grantges
  • I had the same problem just now. Turned out I forgot to add the view to the window. After I did that all works fine.

    — answered August 25th 2011 by James -
    permalink
    0 Comments
  • What does that mean ? Can we ignore this error ? because the app it self works perfect and the user can not see this error!

    — answered July 9th 2011 by Hansjuerg Wuethrich
    permalink
    0 Comments
  • Hi guys,

    I know this post was written 3 years ago, but I found another solution : don't forget to set a width to your view, especially if you work with MVC and Alloy.
    I didn't set any width for my view because the normal layout rules VISUALLY set it to 100%. In fact, the "animation manager" (or whatever it is called) couldn't animate-left my view because it had a width of 0px.
    So don't forget to set the width before using any animation. Hope it will help.

    Cheers.

    — answered September 26th 2013 by Ugo Stephant
    permalink
    1 Comment
    • Thanks Ugo, this just helped me :)

      — commented November 9th 2013 by Phil Smithson
  • I know this is an old thread but I've been playing around with this, maybe it can be helpful. To animate two object simultaneously and not get any warnings is fairly simple. Just insert this code into app.js and play. The code works but it is not cleaned, do not have much time right now …
    Try it yourself. /Jonni

    var self = Titanium.UI.createWindow({
        backgroundColor : "#005494",
        exitOnClose : true
    });
    var view01 = Titanium.UI.createView({
        top : 0,
        height : "100%",
        width : 80,
        backgroundColor : "#FFC900",
        id : "View01",
    });
    var view02 = Titanium.UI.createView({
        top : 75,
        left : 0,
        height : 80,
        width : "100%",
        id : "View02",
        backgroundColor : "#FFC900"
    });
    var view = Titanium.UI.createView({
        top : 64,
        left : 0,
        height : 44,
        width : 320,
        id : "View",
        backgroundColor : "#005494",
    });
    
    var animation1 = Titanium.UI.createAnimation({
    });
    var animation2 = Titanium.UI.createAnimation({
    });
    function ICommandYouToAnimate() {
        animation1 = Titanium.UI.createAnimation({
            "opacity" : 1,
            "duration" : 800,
            "left" : 100,
            "curve" : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT,
        });
        animation2 = Titanium.UI.createAnimation({
            "opacity" : 1,
            "duration" : 800,
            "top" : 200,
            "curve" : Ti.UI.ANIMATION_CURVE_EASE_IN_OUT,
        });
        view01.animate(animation1);
        view02.animate(animation2);
        setTimeout(function() {
            animation1.opacity = 0.5;
            animation2.opacity = 0.5;
            view01.animate(animation1);
        }, 1000);
        setTimeout(function() {
            animation2.opacity = 0.5;
            animation1.opacity = 0.5;
            view02.animate(animation2);
        }, 2000);
        return;
    }
    ICommandYouToAnimate();
    setTimeout(function() {
        self.remove(view02);
        self.remove(view01);
        self.add(view02);
        self.add(view01);
        ICommandYouToAnimate();
    }, 10000);
    self.add(view02);
    self.add(view01);
    self.open();
    
    — answered October 1st 2013 by Jonni Åkesson
    permalink
    0 Comments
  • In my case, I simply added an event listener to solve the problem:

    myViewToAnimate.addEventListener('load',function() {
      // animation code;
    )};
    
    — answered September 5th 2011 by Micah Alcorn
    permalink
    1 Comment
    • This works for an ImageView, but there is no 'load' event for a regular view.

      — commented September 6th 2011 by Micah Alcorn
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.