简体   繁体   English

UINavigationController pop重置根视图控制器的框架

[英]UINavigationController pop resets frame of root viewcontroller

Interface Builder is set up to use autolayout, but no constraints are set for my root view controller. Interface Builder设置为使用自动布局,但没有为我的根视图控制器设置任何约束。 I have a button that moves views around in the root view controller. 我有一个按钮可以在根视图控制器中移动视图。 When I push a new viewcontroller onto the stack and subsequently pop it, the frames of the views on the root view controller are reset to their beginning locations. 当我将一个新的viewcontroller推入堆栈并随后将其弹出时,根视图控制器上的视图框架将重置为其初始位置。

Any theories on why that may be happening? 关于为什么会发生的任何理论?

When you use Auto Layout, the frames of your views are determined by the constraints you set. 使用自动版式时,视图的框架由设置的约束确定。 If you don't modify your constraints and instead manually change your views' frames, then the next time your views are laid out their frames will once again be determined by the constraints set on them (and one time this happens is right before your view controller's view appears on screen, which is what you're seeing). 如果您不修改约束,而是手动更改视图的框架,那么下次对视图进行布局时,框架将再次由对其设置的约束来决定(而这种情况恰好发生在视图之前)控制器的视图出现在屏幕上,这就是您所看到的)。

If you want these frame changes to hold after layout happens, you should modify your constraints (either by changing their constant values or by replacing them with entirely new ones) instead of the views' frames. 如果希望在布局发生后保留这些框架更改,则应修改约束(通过更改其constant数值或用全新的constant数值代替),而不是视图的框架。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 MVYSideMenu弹出到根视图控制器 - MVYSideMenu pop to root viewcontroller UINavigationController:弹出 ViewController Animation 暂停一会儿 - UINavigationController: Pop ViewController Animation pause for a while 故事板 - 没有UINavigationController弹出到根UIViewController? - Storyboard - Pop to Root UIViewController Without UINavigationController? 使用UINavigationController iOS 6弹回到初始viewcontroller时,方向会发生变化 - Orientation changes when pop back to the initial viewcontroller using UINavigationController iOS 6 在标签栏应用程序中弹出到根ViewController - Pop to Root ViewController in Tab bar Application 通过“ UINavigationController”子类正确设置“ Root ViewController” - Correct way setting 'Root ViewController' thru 'UINavigationController' subclass iOS:仅隐藏一个视图控制器的导航栏,它是 UINavigationController 的根目录? - iOS: Hide the navigation bar for only one viewcontroller which is root of the UINavigationController? 弹出根ViewController时如何释放内存,对象,视图控制器 - how to release memory,object,viewcontroller when you pop to root ViewController UINavigationController-弹出 - UINavigationController - Pop 连接到导航控制器时如何将ViewController弹出到根目录 - How to pop ViewController to root when connected to navigation controller
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM