什么时候调用 layoutSubviews? [英] When is layoutSubviews called?

查看:27
本文介绍了什么时候调用 layoutSubviews?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义视图,在动画过程中没有收到 layoutSubview 消息.

I have a custom view that's not getting layoutSubview messages during animation.

我有一个充满屏幕的视图.它在屏幕底部有一个自定义子视图,如果我更改导航栏的高度,它会在 Interface Builder 中正确调整大小.layoutSubviews 在创建视图时被调用,但不会再次调用.我的子视图布局正确.如果我关闭通话状态栏,则根本不会调用子视图的 layoutSubviews,即使主视图确实对其调整大小进行了动画处理.

I have a view that fills the screen. It has a custom subview at the bottom of the screen that correctly resizes in Interface Builder if I change the height of the nav bar. layoutSubviews is called when the view is created, but never again. My subviews are correctly laid out. If I toggle the in-call status bar off, the subview's layoutSubviews is not called at all, even though the main view does animate its resize.

layoutSubviews究竟是在什么情况下被调用的?

Under what circumstances is layoutSubviews actually called?

我将自定义视图的 autoresizesSubviews 设置为 NO.在 Interface Builder 中,我设置了顶部和底部支柱以及垂直箭头.

I have autoresizesSubviews set to NO for my custom view. And in Interface Builder I have the top and bottom struts and the vertical arrow set.

难题的另一部分是必须将窗口设为键:

Another part of the puzzle is that the window must be made key:

[window makeKeyAndVisible];

否则子视图不会自动调整大小.

of else the subviews are not automatically resized.

推荐答案

我将解决方案归结为 Interface Builder 坚持认为无法在打开模拟屏幕元素(状态栏等)的视图上更改弹簧.由于主视图的弹簧已关闭,因此该视图无法更改大小,因此在调用栏出现时整个向下滚动.

I tracked the solution down to Interface Builder's insistence that springs cannot be changed on a view that has the simulated screen elements turned on (status bar, etc.). Since the springs were off for the main view, that view could not change size and hence was scrolled down in its entirety when the in-call bar appeared.

关闭模拟功能,然后调整视图大小并正确设置弹簧会导致动画发生并调用我的方法.

Turning the simulated features off, then resizing the view and setting the springs correctly caused the animation to occur and my method to be called.

调试时的一个额外问题是,当通过菜单切换通话状态时,模拟器会退出应用程序.退出应用 = 没有调试器.

An extra problem in debugging this is that the simulator quits the app when the in-call status is toggled via the menu. Quit app = no debugger.

这篇关于什么时候调用 layoutSubviews?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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