如果更改帧大小,IOS Label Animation将不会在标签内部绘制

时间:2013-06-19 14:46:52

标签: ios animation uilabel

尝试使用基本动画来移动和缩小标签尺寸。如果未更改标签的帧大小,则动画可以正常工作。但是如果缩小框架的尺寸,则只绘制边框。

你可以看到注释行,如果用下面的行切换工作正常,因为只绘制标签的边框。此处的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];
}

];

1 个答案:

答案 0 :(得分: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]; } ];
}