Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect autorotation inside UIView subclass

I'm creating a subclass of UIView that needs to relayout its subviews when the orientation changes.

it needs to be able to "plug in anywhere" without any extra code so I'd rather not rely on the UIViewController methods to detect the autorotation

Is there anyway for the UIView to know when the orientation has changed?

like image 732
Matt Zera Avatar asked Aug 26 '13 07:08

Matt Zera


1 Answers

How about a notification like this to detect the orientation change??

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil]; 

But, before that you need to register for generating notifications like this.

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
like image 161
Dinesh Raja Avatar answered Nov 10 '22 19:11

Dinesh Raja