【问题标题】:CGAffineTransform not working in UIView Animation Completion BlockCGAffineTransform 在 UIView 动画完成块中不起作用
【发布时间】:2014-03-12 17:11:02
【问题描述】:

我正在尝试使用 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;
    }];

【问题讨论】:

  • 您在该完成块中同时运行两个动画。第二个不应该在第一个的完成块中吗?
  • 刚刚试过了,还是不行:(
  • sizeToFit 调用不应该真的存在,尽管我不确定它们会影响动画。 “不工作”是什么意思?
  • 拿出来还是一无所获。不像在动画中那样工作实际上并没有动画。我已经在块中放置了其他测试动画,它们工作正常。所以我认为它与变换属性有关
  • 展示如何init你的self.monthLabel

标签: ios objective-c animation uiview cgaffinetransform


【解决方案1】:

你没有解释变换动画有什么问题。但在我的情况下,转换根本没有动画,它会转换到最终状态,就好像持续时间是0.0。 我可以通过添加选项来修复它:

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

如果有帮助,请告诉我。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-07-14
    • 2014-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多