繁体   English   中英

如果更改框架大小,IOS标签动画将不会在标签内绘制

[英]IOS Label Animation will not draw inside of label if changing the frame size

试图获得基本的动画来移动和缩小标签。 如果不更改标签的帧大小,动画效果会很好。 但是,只有在缩小框架尺寸时才绘制边框。

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

];

最终使标签/视图的图像动画化。 这是代码,也许会帮助某人。 假设包括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]; } ];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM