ViewWillTransitionToSize: vs willTransitionToTraitCollection:

Can someone explain the differences between the two methods? The documents for the UIViewController explicitly indicate that viewWillTransitionToSize should be used to control the turns, but by going to the UIContentContainer page, the willTransitionToTraitCollection method makes a confusing entry.

I think I understand the conceptual difference between changing the size class (changing the collection of attributes) and changing the size, but I'm not sure which method to implement in which circumstances. An explanation from the UIKit wizard would be helpful!

+8
ios uikit rotation uiviewcontroller
source share
1 answer

Whenever you want to do something to respond to a user spinning their device, you must use viewWillTransitionToSize , if you do, you know for sure that your actions are executed, as it is called every time your application window changes its size .

If you want to act only when changing the collection of tags, for example, if you have a specific collectionViewLayout for a class of size Compact , and another that you want to use for Regular , you will willTransitionToTraitCollection .

If the collection of tags changes, the size also changes. But this does not work the other way around. Portrait iPad and landscape iPad have the same features, but different sizes. Add multitasking to the mix, and you have a number of sizes that will be displayed for only two traitCollection size traitCollection .

+16
source share

All Articles