使用UILabel调整uiview的大小和动画 [英] resize uiview with UILabel and animate it correctly
问题描述
我有一个UIView作为一个UILabel的容器,像这样:
I have a UIView as container with a UILabel inside like this:
------------- ---------
| | | |
|Label text | |Label..|
| | --> | |
| | | |
| | | |
------------- ---------
现在当我使用:
UIView animateWithDuration:animations:
并尝试设置UIView(其中包含UILabel)的宽度更小,那么在动画期间UILabel突然替换为...,而没有平滑过渡到它。我设置UILabel自动调整掩码为UIViewAutoresizingFlexibleWidth,UIViewAutoresizingFlexibleRightMargin保持左边,并将内容模式设置为左边。
and try to set the width smaller of the UIView (which contains the UILabel) then during the animation the UILabel suddenly replace with "..." without having smooth transition to it. I setup the UILabel autoresizingmask to UIViewAutoresizingFlexibleWidth, UIViewAutoresizingFlexibleRightMargin to keep it left and set the contentmode to left.
尝试其他内容模式,如:缩放填充,
Trying other content mode like:Scale to fill, Aspect fit, Aspect fill doesnt solve my problem either, as they scale the text and then it looks strange.
任何人都有一个想法如何获得平滑过渡的UILabel?我不知道如何解决我的问题,因为他们缩放文本,然后看起来很奇怪。
Anybody have an idea how to get smooth transition for the UILabel?
推荐答案
我在一段时间之前用我描述的方式动画了我的标签,但是你必须付出一些代价。
基本思想:
- 使用clipsToBounds:YES添加标签到containerview。
- 不要为标签框架设置动画,而是为containerview的框架设置动画,以便标签具有平滑过渡。
- 为Elipsis(...)使用单独的标签,因此您也可以对此部分进行动画处理。
I animated my label the described way some time ago, but you have to put some afford in it. Basic idea: - Add the label to a containerview with clipsToBounds:YES. - Do Not animate the label frame, instead animate the frame of the containerview, so your label will have a smooth transition. - Use a seperate Label for the Elipsis (...) so you can animate this part too.
这篇关于使用UILabel调整uiview的大小和动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!