0

试图获得一个基本的动画来移动和缩小标签。如果标签的帧大小没有改变,动画效果很好。但仅在缩小框架时才绘制边框。

您可以看到注释行,如果与下面的行切换可以正常工作,因为只绘制了标签的边框。这里的 ToFrame 比 fromFrame 小。

[UIView animateWithDuration:1.5 animations:
^{
    label = [[UILabel alloc] initWithFrame:fromFrame];
    [label setBackgroundColor:color];
    label.text = text;
    label.layer.cornerRadius = 10;
    label.layer.borderWidth = 4;
    [self.view addSubview:label];
    label.adjustsFontSizeToFitWidth = true;

    CGRect frame = label.frame;
    //frame.origin.y = self.view.frame.size.height;
    frame = toFrame;
    label.frame = frame;
}
completion:^ (BOOL finished)
{
    [label removeFromSuperview];
}

];
4

1 回答 1

0

结束了对标签/视图的图像进行动画处理。这是代码,也许会对某人有所帮助。假设 ARC 和 Quartz 包括在内。

- (void) animateFromFrame:(CGRect)fromFrame toFrame:(CGRect)toFrame andView:(UIView*)view
{
    UIGraphicsBeginImageContext(view.bounds.size);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    UIImageView* imageView = [[UIImageView alloc] initWithImage:image];

    imageView.frame = fromFrame;
    imageView.layer.cornerRadius = 10;
    imageView.layer.borderWidth = 4;
    [self.view addSubview:imageView];

    [UIView animateWithDuration:1.0 delay:0.25 options:nil animations: ^{ imageView.frame = toFrame; } completion:^ (BOOL finished) { [imageView removeFromSuperview]; } ];
}
于 2013-06-27T18:44:24.447 回答