iOS版 - 更新推另一个视图控制器然后返回工作后自动布局约束不变站 [英] iOS - Updating auto layout constraint constant stops working after pushing another view controller then returning

查看:313
本文介绍了iOS版 - 更新推另一个视图控制器然后返回工作后自动布局约束不变站的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在IB(故事板)设计一个UIViewController有包含几个控件一个UIView。 UIView的具有自动布局约束来解决它的高度。在我的UIViewController子类我有一个 IBOutlet中NSLayoutConstraint (伊娃)连线到高度约束,这样我可以在code调整。根据用户的事件,我展开/修改约束的 80和44之间的财产,这也滑上/下它被限制在一个UITableView缩小的UIView的高度UIView的底部。我已经使用这个技术之前,所有工作得很好。

I have a UIViewController designed in IB (Storyboard) that has a UIView containing a few controls. The UIView has an auto layout constraint to fix its height. In my UIViewController subclass I have an IBOutlet NSLayoutConstraint (ivar) wired to the height constraint so that I can adjust it in code. Depending on user events, I expand/shrink the height of the UIView by modifying the constraint's constant property between 80 and 44, which also slides up/down a UITableView which is constrained to the bottom of the UIView. I have used this technique before and all works well.

我现在用了的UITabBar父容器内的UIViewController本的UIViewController的4个实例。当的UITabBar标签选择改变时,我在适当的情况下使用交换 insertSubView 。问题是,UIView的失败展开/在第一胎视图控制器标签页缩水。在其他3个标签页情况下,它工作正常。另外在三个标签页,其中它的工作原理,如果我把另一个视图控制器压入堆栈,然后恢复,UIView的的大小调整不再工作。

I am now using 4 instances of this UIViewController within a parent container UIViewController with a UITabBar. When the UITabBar tab selection is changed, I swap in the appropriate instance using insertSubView. The problem is that the UIView fails to expand/shrink in the first child view controller tab page. In the other 3 tab page instances it works fine. Also in the 3 tab pages where it works, if I push another view controller onto the stack and then return back, the resizing of the UIView no longer works.

在的情况下展开/收缩失败,我已经使用的NSLog 来监控约束的恒属性,它是在每一个实例被改变,但UIView的高度不被影响。至于如果约束不再设置为在UIView的??

In the case where the expand/shrink fails, I have used NSLog to monitor the value of the constraint's constant property and it is being changed in every instance, but the height of the UIView is not being affected. As if the constraint is no longer set to work on the UIView??

我用X code 5.1和我的应用程序打靶iOS7。

I'm using Xcode 5.1 and my app is targetting iOS7.

推荐答案

最后由调用<$ c中的 animateWithDuration 块内改变code解决了这个问题$ C> layoutIfNeeded 容器控件刷新的控件的位置。基本上,而不是只调用 layoutIfNeeded 父容器控件,我现在请 layoutIfNeeded 在每个孩子的控制其位置由于将变为约束常数被修改。现在,所有控件正确定位上所有4个标签页,甚至从另一个视图控制器返回后。

Finally solved this problem by changing the code within the animateWithDuration block which calls layoutIfNeeded on the container control to refresh the position of the controls. Basically instead of just calling layoutIfNeeded on the parent container control, I now call layoutIfNeeded on each of the child controls whose position will change due to the constraint constant being modified. Now all controls reposition correctly on all 4 tab pages and even after returning from another view controller.

这篇关于iOS版 - 更新推另一个视图控制器然后返回工作后自动布局约束不变站的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆