问题
Found if use XCode 8 XIB file, the UIView initWithCoder will get frame (0, 0, 1000, 1000) instead of the XIB frame size setting.
Check the diff of XIB xml file it will add
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMaxY="YES"/>
and remove rect frame settings such as
<rect key="frame" x="110" y="0.0" width="20" height="17"/>
Removing rect frame setting is the major root cause to get width 1000 and height 1000 in the initWithCoder.
Therefore, any related size calculation, we need to handle in layoutSubviews
.
来源:https://stackoverflow.com/questions/39631583/xcode8-initwithcoder-frame-size