UILabel does not animate inside UIView, autolayouts used

前端 未结 2 860
感动是毒
感动是毒 2020-12-21 06:42

I have a very simple application. It contains a red view and a green label inside it. There is also a button that runs animation. I animate the red view by changing its widt

相关标签:
2条回答
  • 2020-12-21 07:30

    It seems like I've found the root of the problem. Constraints are not a trouble, UILabel is.

    If you replace UILabel in my project with simple UIView it will animate smoothly as expected. It's a question of UILabel content animation. You can reach correct animation behaviour set label.contentMode = UIViewContentModeCenter but it looks ugly.

    The best way to solve this problem - not try to change size of UILabel during animation. Try to invent some other behaviour. In my case I change UILabel's alpha to 0 and x position to greater then container view's width.

    Please find more details about UILabel animating here.

    0 讨论(0)
  • 2020-12-21 07:36

    I have took a look at your project. I have not that much experience with setting constraints from editor but I would highly recommend you in case of troubles try to do it in code. Personally I would animate constraint on width of this red view and set constraints on the label's margins using visual format it will be something like: @"H:|[label]|" and add this this constraint to red view. That should solve the problem.

    0 讨论(0)
提交回复
热议问题