UIView and AutoresizingMask ignored

前端 未结 1 837
我在风中等你
我在风中等你 2021-01-02 11:37

First time posting on stack overflow.

I\'ve spent hours scouring over many Google searches and have, at this point, practically memorized the UIView and UIViewContro

相关标签:
1条回答
  • 2021-01-02 12:09

    Well, sure enough, it was my own fault.

    Lesson number one: You are not doing yourself any favors by staying up all night trying to fix broken code. Get some rest! Drink more water! You will only probably make things worse if you keep trying to force your brain to perform complicated algorithmic strategy and logic past its bed-time.

    Turns out I had a rogue UIView toward the bottom of the view hierarchy that did not have the autoresize property set at all. I thought I had looked through everything, but turns out that I missed one. (Just one little view, and an entire day shot!)

    I can say for anyone who comes along later with similar frustration, that Autoresizing does indeed work as documented. If you think that "something is not being called" then you are probably looking in the wrong place. Also, the UIViewAutoresizingMask enum constants are not used exactly like they are in Interface Builder. In IB, you "lock" margins, whereas in setting them programmatically, the locked margins are assumed by default and you "unlock" them by setting it as "Flexible". So for example, setting only the FlexibleWidth and FlexibleHeight bits is equivalent to enabling all autoresizing options in IB. By throwing in any of the margin masks (i.e. UIViewAutoresizingFlexibleLeftMargin) you are "deselecting" the corresponding margin autoresizing option in IB. (I've seen many other posts floating around where this seemed to be a major point of confusion for some folks.)

    During my research, however, I did notice that there does not seem to be any sort of event, message, notification, or otherwise when a UIView gets resized, whether automatically or not. While not necessary for resizing subViews, it would be nice to know when it's happening in the situation where you would like to cause a scrollView or tableView to scroll should it's frame size ever change. I know one can easily do this when the keyboard pops up, because there is a notification system around that as well as the TextField delegate methods. So maybe a topic for another post...

    Anyway, thank you everyone who participates on StackOverflow!

    0 讨论(0)
提交回复
热议问题