更改标签与动画帧的大小 [英] Change size of label's frame with animation

查看:174
本文介绍了更改标签与动画帧的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有一个流畅的动画效果来更改标签的的宽度(不fontSize的或东西)的方式。

I would like to know if there is a way to change a label's frame's width (not the fontSize or something) with a smooth animation.

我已经尝试过以下,即没有(明显)不工作:

I already tried the following, that did (obviously) not work:

_myLabel.frame = CGRectMake(139,193,42,21);

[UIView animateWithDuration:1 animations:^ {
    _myLabel.frame = CGRectMake(139, 193, 100, 21);
} completion:^(BOOL finished) {
}];

那么,运行该code是它改变了宽度预期,但没有任何动画完成后,基本上发生了。

So what basically happened after running this code was that it changed the width as expected but without any animation.

任何想法?

推荐答案

您不能更改标签的帧大小...
可以达到正确的动画行为..设置label.contentMode = UIViewContentModeCenter但它看起来丑陋

You can't change the frame size of labels... You can reach correct animation behavior.. set label.contentMode = UIViewContentModeCenter but it looks ugly

但你可以...

  • change is the bounds, rather than the frame http://stackoverflow.com/a/3304220
  • add an UIView and then add UILabel as its subview and animate UIView http://stackoverflow.com/a/15639093 and http://stackoverflow.com/a/22224630
  • Use a CGAffineTransform to do this but have some ugly side effects like distorting the text on the label http://stackoverflow.com/a/13066366
  • change the font of UILabel with transform Animation Animating UILabel Font Size Change

这篇关于更改标签与动画帧的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆