UILabel 动画 - 扩展帧动画未在底部拉伸
我有以下代码:
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
没什么问题。 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.