Is here a way to run a method when the iOS devices orientation changes?
I would like to change only some objects orientations on the screen, and not others.
What delegates do I use etc.
Cheers -A newbie
Some device configurations can change during runtime (such as screen orientation, keyboard availability, and when the user enables multi-window mode). When such a change occurs, Android restarts the running Activity ( onDestroy() is called, followed by onCreate() ).
This inherited UIViewController method which can be overridden will be trigger every time the interface orientation will be change.
Detecting Orientation Changes in Javascript Should you need to simply detect when a user changes orientation, you can use the following event listener: screen. orientation. addEventListener("change", function(e) { // Do something on change });
Another most common solution to dealing with orientation changes by setting the android:configChanges flag on your Activity in AndroidManifest. xml. Using this attribute your Activities won't be recreated and all your views and data will still be there after orientation change.
Depends when you want to react:
If before rotation, override from UIViewController:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
// do something before rotation
}
If you want to perform something after rotation:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
// do something after rotation
}
Reference:
http://developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/Reference/Reference.html#//apple_ref/occ/instm/UIViewController/willRotateToInterfaceOrientation:duration:
UIDevice
posts UIDeviceOrientationDidChangeNotification
UIApplication
posts UIApplicationWillChangeStatusBarOrientationNotification
and UIApplicationDidChangeStatusBarOrientationNotification
and has a related delegate callback for each.
UIViewController
receives several orientation related calls triggered by the UIDevice notification if the view controller is part of the controller hierarchy managed by a window.
If you are already using a UIViewController, implement some of the orientation related methods, otherwise register for the UIDevice notifications. The most important UIViewController method is shouldAutorotateToInterfaceOrientation
because if that return NO
the others are not called.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With