-->

why might layoutSubviews NOT automatically be call

2019-02-18 15:55发布

问题:

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.