Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overridden traitCollectionDidChange() method of UIView subclass not called when rotating

Tags:

ios8

The document of UITraitEnvironment says:

This method is called automatically when the current trait collection changes. Overriding this method provides you with a way to customize behavior when the trait collection associated with the view changes. If you do not override this method, no special behavior is performed.

But when I rotate the simulator this overridden method in my UIView subclass is not called.

My code looks like:

override func traitCollectionDidChange(previousTraitCollection: UITraitCollection?) { 
    super.traitCollectionDidChange(previousTraitCollection)

    println("______________________________")
}

Did I miss anything? Or I understand the API doc wrongly? thx for shedding light on it.

like image 763
Golden Thumb Avatar asked Nov 30 '22 18:11

Golden Thumb


1 Answers

Are you tested on the iPad?

Probably because on the iPad the trait collection are all Regular for vertical and horizontal on both portrait and landscape.

Try this method it should work.

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

like image 186
Hungju Lu Avatar answered Dec 17 '22 23:12

Hungju Lu