0
votes

I am trying to animate a UILabel with a transform property. It seems to work fine in the main animation. But once I try animating in the main animations completion block

UILabel *dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(point.x, point.y, 50, 20)];
    dateLabel.text = [NSString stringWithFormat:@"%d", date];
    dateLabel.textColor = [UIColor whiteColor];
    dateLabel.textAlignment = NSTextAlignmentCenter;
    [self addSubview:dateLabel];
    [UIView animateWithDuration:.4 animations:^{
        dateLabel.frame = CGRectMake(self.frame.size.width/2 - 25, 10, 50, 70);
        self.calendar.frame = CGRectMake(0, 800, 320, 320);
        dateLabel.font = [UIFont fontWithName:@"Bariol-Bold" size:28];
    } completion:^(BOOL finished) {

        [UIView animateWithDuration:.5 animations:^{
            self.monthLabel.transform = CGAffineTransformMakeScale(1.2,1.2);
            [self.monthLabel sizeToFit];
        } completion:nil];

        [UIView animateWithDuration:.5 animations:^{
            self.monthLabel.transform = CGAffineTransformMakeScale(1.15,1.15);
            [self.monthLabel sizeToFit];
        } completion:nil];

        calendarAnimation = NO;
    }];
1
You're running two animations simultaneously in that completion block. Shouldn't the second one be in the completion block of the first?jrturton
just tried that, still didn't work :(user2752687
The sizeToFit calls shouldn't really be there, though I'm not sure they would affect the animation. What do you mean by "not working"?jrturton
Took it out still nothing. Not working as in the animations don't actually animate. Ive put other test animations in the block and they work fine. So I'm thinking its something with the transform propertyuser2752687
Show how to init your self.monthLabel.Unheilig

1 Answers

0
votes

You don't explain what is wrong with the transform animation. But in my case, the transform was simply not animating, it would transition to the final state as if the duration was 0.0. I was able to fix it by adding the options:

[UIView animateWithDuration:0.25 delay:0.0 options:UIViewAnimationOptionOverrideInheritedDuration|UIViewAnimationOptionOverrideInheritedCurve animations:^{
    // animate transform here
    } completion:^(BOOL finished) {
    // finished;
}];

Let me know if it helps.