Animating a view created in IB using Autolayout

懵懂的女人 提交于 2019-12-13 04:10:08

问题


I have a view with a lot of labels and buttons which are created on code because in IB is too complicated. This works ok.

In IB I also created an input view which I want to appear from the bottom by the tap on a button. Very much like a keyboard if you will. Because this input view is strigth forward, it has been created on IB and it contains sliders, labels, etc. I haven't added it as a subview of self.view on IB.

By the tap of the button, I set up all the constrains for the input view: I set the width, I set it on the bottom of the self.view with vertical size, then I remove this constraint, I add the actual heigth and then I animate with [self.view layoutIfNeeded].

The thing is that the input view itsef animates correctly, but its subviews not so much. They kind of appear at once.

I have tried adding a input view programmatically, with only one switch. It animates quite nicely.

I'm guessing that there is a problem with the constrains between the controls and their superView. But I'm not sure about it, because although they do not animate correctly, they are on the correct place and witht the correct proportions. I guess I'm missing something here. Maybe it's not a good idea to mix IB set controls and views and programmatically modifying them?

Does somebody have any experience with that?

Thanks in advance,


回答1:


I suggest you post to Apple's dev boards on this subject. I've seen several posts there recently. The Apple Engineers who replied said that with Autolayout, you basically give autolayout ownership of your view's center, size, and sometimes, transform.

To animate views that use autolayout, you should apparently use UIView block animation and animate the constraint settings on the views. The system will then animate the changes you make.

Not sure about adding new views programmatically and having them animate into place however.



来源:https://stackoverflow.com/questions/14559677/animating-a-view-created-in-ib-using-autolayout

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!