Chris G. Chris G. - 1 year ago 129
iOS Question

traitCollectionDidChange: Called even I dont have any changes

Do you know why

is called even with no Size Class changes.

Selecting a UILabel, I have in my storyboard Attribute Inspector / Installed check for the UILabel. No special cases for installing according to Size Class.

Therefore I dont understand why
is called when I rotate the device?

Yes, it is called after viewDidLod, but also every time I rotate the device/ emulator.

If I wanted to react to rotation I would use

Update: Hmm, re-thinking this. I guess that Size Class is actually also changing when you rotate an iPhone.

Can you think of traitCollectionDidChange as a specialised method of viewWillTransitionToSize - facilitating thresholds for telling when we are crossing Size Class boundaries?

Answer Source

The size class will change if you rotate an iPhone, but won't change if you rotate an iPad (which has a regular size class for both horizontally and vertically).

Rotation is considered to be a change in the interface environment, therefore traitCollectionDidChange is called.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download