UILabel 动画 - 扩展帧动画未在底部拉伸

发布于 2024-10-10 03:54:16 字数 848 浏览 0 评论 0原文

我有以下代码:

desc = [[UILabel alloc] initWithFrame:CGRectMake(134, 5, 185, 60)];
[desc setNumberOfLines:20];
[dataView addSubview:desc];
desc.text =@"1111\n2222\n3333\n4444\n5555\n6666\n7777\n8888" ;

数据不适合标签,所以我看到类似以下内容:

1111
2222
3333
4444...

我还有一个按钮,当您单击它时,我想展开标签,以便所有数据都可见。为此,我有以下代码:

CGSize newDescSize = [desc.text sizeWithFont:[UIFont italicSystemFontOfSize:12] constrainedToSize:CGSizeMake(185, 400)];

[UIView beginAnimations:@"expandDesc" context:nil];
[UIView setAnimationDuration:1.0];

CGRect frame = desc.frame;
frame.size.height=newDescSize.height;
desc.frame=frame;

[UIView commitAnimations];

它工作正常,只是动画从视图开始:

3333
4444
5555
6666

并且在展开时,两条线都添加在底部和顶部,因此动画不流畅,我希望文本将从原始文本展开,并在底部添加线条。

有谁知道我做错了什么?

I have the following code:

desc = [[UILabel alloc] initWithFrame:CGRectMake(134, 5, 185, 60)];
[desc setNumberOfLines:20];
[dataView addSubview:desc];
desc.text =@"1111\n2222\n3333\n4444\n5555\n6666\n7777\n8888" ;

the data is not fitting in the label so I see something like:

1111
2222
3333
4444...

I also a button that when you click it i want to expand the label so all the data is visible. For that I have the following code:

CGSize newDescSize = [desc.text sizeWithFont:[UIFont italicSystemFontOfSize:12] constrainedToSize:CGSizeMake(185, 400)];

[UIView beginAnimations:@"expandDesc" context:nil];
[UIView setAnimationDuration:1.0];

CGRect frame = desc.frame;
frame.size.height=newDescSize.height;
desc.frame=frame;

[UIView commitAnimations];

It works fine except that the animation starts from the view:

3333
4444
5555
6666

and while expanding both lines are added on the bottom and the top, so the animation is not smooth, I want the the text will expand from the original text and lines will be added at the bottom.

does anyone know what i'm doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼眸里的快感 2024-10-17 03:54:16

没什么问题。 UILabel 的 -drawRect: 方法经过优化,因此不会在其边界之外绘制。简而言之,这意味着你不会有一个平滑的过渡,它会从两端出现抖动。如果不使用自定义类,我不知道你能做什么。

Nothing is wrong. The -drawRect: method of the UILabel is optimized so that It doesn't draw outside its bounds. This, simply put, means that you won't have a smooth transition for it, it will jerk from both ends. Without using a custom class, I don't know what you can do.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文