Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what method will called when we start to rotate device and after it finished

i want to detect a rotation process on ipad programmatically. In this case i want to set a boolean into yes, when the rotation will begin, and set it false after the rotation did ending. Is there any method that called when the rotation will begin and the rotation did ending?

like image 627
R. Dewi Avatar asked Sep 16 '11 11:09

R. Dewi


People also ask

Which methods is are called after orientation changes?

So when the device orientation changes, first the Activity will disappear for a millisecond when the onPause(), OnStop, and onDestroy() methods are called. After a few milliseconds, the activity will be restarted when the onCreate(), onStart() and onResume() methods are called.

What is the order that the lifecycle events are called after the device is rotated?

After rotate, Log after rotate the screen. You can notice here onPause is executed. onStop is executed, onDestroy is executed. and soon after that onCreate, onStart and on Resume is again executed.

Which method is used to screen orientation?

from portrait => landscape mode).

What does it mean to rotate your device?

Device rotation behavior refers to when a user rotates their tablet or mobile device, from portrait to landscape mode or vice versa. This behavior can reflect either engagement or frustration. If viewing a video, for example, it is commonplace to rotate your device into landscape mode for a better viewing experience.


2 Answers

From Apple Docs:

Sent to the view controller just before the user interface begins rotating.

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 

Sent to the view controller after the user interface rotates:

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

See more here: UIViewController Class Reference -> Responding to View Rotation Events

ATTENTION: This is deprecated, see this post

like image 132
Nekto Avatar answered Sep 20 '22 00:09

Nekto


For newcomers to this post, the methods suggested by Nekto have become deprecated in iOS 8. Apple suggests to use:

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

You can use the "size" parameter as an easy way to get whether it is transitioning to portrait or landscape.

i.e.

if (size.width > size.height) {     // Position elements for Landscape } else {     // Position elements for Portrait } 

More info is availablein the Docs.

like image 40
julianwyz Avatar answered Sep 20 '22 00:09

julianwyz