0

I have a UILabel that I show / hide. I want to show the label, pause for a few seconds and hide it. This code ISN'T working. It removes the view as soon as the animation finished (instantly)

-(void) show
{
    [UIView animateWithDuration:.5f delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

                    CGRect newFrame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 44.0f);
                    self.frame = newFrame;

    }                completion:^(BOOL finished){

                            [self hideAndRemove];

    }];

}

-(void) hideAndRemove
{
    [UIView animateWithDuration:.5f delay:2.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

        CGRect frame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 0.0f);
        self.frame = frame;

    }                completion:^(BOOL finished){

        // nothing

    }];
}

However, if I try some other animation on the frame, the delay works and the frame change is animated:

-(void) show
{
    [UIView animateWithDuration:.5f delay:0.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

                    CGRect newFrame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 44.0f);
                    self.frame = newFrame;

    }                completion:^(BOOL finished){

                            [self hideAndRemove];

    }];

}

-(void) hideAndRemove
{
    [UIView animateWithDuration:.5f delay:2.0f
                        options:UIViewAnimationOptionCurveEaseIn  animations:^{

        CGRect frame = CGRectMake(0.0f, 64.0f, [UIScreen mainScreen].bounds.size.width, 250.0f);
        self.frame = frame;

    }                completion:^(BOOL finished){

        // nothing

    }];
}
fansonly
  • 1,150
  • 4
  • 14
  • 29

1 Answers1

0

I don't know what the problem might be, but I think it comes from the frame height who shouldn't be set to 0.

Why not using [UILabel setAlpha:0] to hide your label, and [UILabel setAlpha:1] to show it back ? It seems cleaner than changing its frame height to 0, and it animates nicely.

Pierre
  • 372
  • 2
  • 16
  • But the animations work to grow the frame. Just not to hide it. I'd like to shrink the frame if possible. – fansonly Jul 28 '14 at 23:27