chris
chris

Reputation: 16443

position of UIView after rotation

I have a custom UIView subclass without a corresponding UIViewController. I use this class in various places in my app. When I rotate the device I need to reposition the view. I understand this is normally done with the willAnimateRotationToInterfaceOrientation:duration: method, but that's a part of the UIViewController class and not UIView. My question is, is there a way for my UIView to reposition itself without having to implement a corresponding UIViewController?

Upvotes: 0

Views: 457

Answers (1)

bturner
bturner

Reputation: 514

you application receives notifications from the device when it rotates. you can tell the device to begin generating these notifications for you using

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

and then you can register for the notification using

[NSNotificationCenter default] addObserver:self selector:@selector(doThisWhenRotates:) name:addObserver:selector:name:object: object:nil];

HOWEVER, i wouldn't recommend that. if you really want to follow MVC, you should have a controller to handle this type of stuff for the view.

but if you need to, you can do it the way listed above.

Upvotes: 1

Related Questions