RayChen RayChen - 6 months ago 87
iOS Question

traitCollectionDidChange not called when multitasking

I'm work on adopting multitasking to support split view for app. But I find the traitCollectionDidChange not called when app is on the right. Does anyone have idea about this?

Answer

Have you tried the viewWillTransitionToSize method? This is used to notify the container that the size of its view is about to change.

Objective-C

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id<UIViewControllerTransitionCoordinator>)coordinator

Swift

func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) {
    coordinator.animateAlongsideTransition(nil, completion: {
    if UIDevice.currentDevice().orientation.isLandscape.boolValue {
        print("landscape")
    } else {
        print("portrait")
    }
}