CGAffineTransform在UIView动画完成块中不起作用

时间:2014-03-12 17:11:02

标签: ios objective-c animation uiview cgaffinetransform

我正在尝试使用transform属性为UILabel设置动画。它似乎在主动画中运行良好。但是,一旦我尝试在主动画完成块中动画

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 个答案:

答案 0 :(得分:0)

您没有解释变换动画的问题。但在我的情况下,转换根本就不是动画,它会转换到最终状态,就像持续时间是0.0一样。 我能够通过添加选项来修复它:

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

如果有帮助,请告诉我。