why might layoutSubviews NOT automatically be called on a view when its frame is set?

依然范特西╮ 提交于 2019-12-01 06:42:15

问题


I have a view. It is part of a large and complex project. When the frame of my view is set, layoutSubviews is not automatically called.

Playing around with this, I tried putting the following method into my view:

-(void) setFrame: (CGRect) frame {
    NSLog (@"setting frame");
    [super setFrame: frame];
    [self setNeedsLayout];
}

At this point, layout was redone when the frame was set, as expected. And if I commented out the setNeedsLayout line, layout was not done. Furthermore, when I click on "step into" at the line where super is called, the debugger does not step into anything. So as far as I can tell, super's setFrame method is not being overridden.

FWIW, I also did a small test project in which I changed the frame of a view. In this case, layoutSubviews was called when I did that. [setNeedsLayout was not called in my test project.] So something in my large project is changing the behavior. But I don't know what that something is.

Can anyone explain what might be going on?

EDIT: to clarify, my frame change is changing the view's height. The width is not changed.

来源:https://stackoverflow.com/questions/7921610/why-might-layoutsubviews-not-automatically-be-called-on-a-view-when-its-frame-is

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