Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: UIView animation ignores delay

I have a problem with very simple UIView animation:

- (void)showView:(CGFloat)delay
{
    [UIView animateWithDuration:1.0 delay:delay options:0 animations:^{

        // self.alpha = 0.5; // Works OK with delay
        self.frame = CGRectMake(100, 100, 100, 30); // delay is ignored
    } completion:nil];
}

delay could be set to 1000 and still view is animated immediately. But somehow it works fine with alpha (without setting frame).

like image 242
Dawid Avatar asked Nov 22 '25 08:11

Dawid


1 Answers

The frame is probably being set for you, perhaps by layout being performed by the superview, or this view itself. You haven't said how you're adding this view or what it does so its difficult to give specific advice, but in general terms:

  • Don't let a view be in control of its own frame - this is the superview's or view controllers responsibility. A view can have a preferred size, but the rest is outside.
  • it's usually better to animate bounds and / or centre instead of frame, particularly if you're ignoring the first point.
  • For presentation type animations, it may be better to animate the transform instead - either translation or scale, depending what your animation is.
like image 62
jrturton Avatar answered Nov 24 '25 22:11

jrturton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!