3

I'd like to implement a custom UIDynamicBehavior that makes a view "burst". To do that I need to fade it out and scale it to 2x its size.

I do this by setting the view's alpha and bounds in the action block. However, how do I know how often the action block is called? The docs say "on each tick", but how many?

I added a counter. With no other animations, the block is called 30 times. With a few gravity and dynamic behaviors, it is called 500 times.

I also don't see how the UIDynamicAnimator knows when its behaviors are "done" moving stuff around. Can anyone shed some light on this?

The code below works sometimes, but other times the behavior stops before the view is animated completely (i.e. it is still visible).

self.action = ^{

        static NSInteger count = 0;
        NSLog(@"animation tick: %d", count);
        count++;

        UIView *view = (UIView*)[weakSelf.items lastObject];
        view.alpha = view.alpha - 0.1;

        CGRect bounds = view.bounds;
        bounds.size.width += 1;
        bounds.size.height += 1;
        view.bounds = bounds;

    };
Mark
  • 6,647
  • 1
  • 45
  • 88

1 Answers1

0

For detecting when the animation has finished you could try this:

__weak Entity *weakSelf = self;
self.behavior.action = ^{
    if (weakSelf.center.x == weakSelf.lastPosition.x && weakSelf.center.y == weakSelf.lastPosition.y) {
        NSLog(@"end of dynamic movement");
    }
    weakSelf.lastPosition = weakSelf.center;
};

Or check another value that you are changing.

richy
  • 2,716
  • 1
  • 33
  • 42