-1

I need to get orientation of iOS device for each time iOS device changes orientation remember not on launch of app or at loading time, for every single time device change orientation i need to register it .

Mihir Gurjar
  • 375
  • 1
  • 7
  • @Prince [link](http://stackoverflow.com/questions/9122149/detecting-ios-uidevice-orientation) These is link from where i tried code, code used was the answer to question ! – Mihir Gurjar Feb 26 '15 at 12:18

2 Answers2

2

you have to Listen/observe/watch for device orientation changes UIDeviceOrientationDidChangeNotification,

See same question here

Mohd Prophet
  • 1,511
  • 10
  • 17
Yahya
  • 501
  • 4
  • 8
0

As per apple UIKit Framework Reference following method called every time when device orientation changed.

For iOS8 and later

Notifies the container that the size of its view is about to change. (required)

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

Parameters

size - The new size for the container’s view.

coordinator - The transition coordinator object managing the size change. You can use this object to animate your changes or get information about the transition that is in progress.

Discussion

UIKit calls this method before changing the size of a presented view controller’s view. You can override this method in your own objects and use it to perform additional tasks related to the size change. For example, a container view controller might use this method to override the traits of its embedded child view controllers. Use the provided coordinator object to animate any changes you make.

If you override this method in your custom view controllers, always call super at some point in your implementation so that UIKit can forward the size change message appropriately. View controllers forward the size change message to their views and child view controllers. Presentation controllers forward the size change to their presented view controller.

For iOS2 upto iOS8

Sent to the view controller after the user interface rotates.

Deprecation Statement

Use viewWillTransitionToSize:withTransitionCoordinator: to make interface-based adjustments.

Declaration

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation

Parameters

fromInterfaceOrientation - The old orientation of the user interface. For possible values, see UIInterfaceOrientation.

Discussion

Subclasses may override this method to perform additional actions immediately after the rotation. For example, you might use this method to reenable view interactions, start media playback again, or turn on expensive drawing or live updates. By the time this method is called, the interfaceOrientation property is already set to the new orientation. Your implementation of this method must call super at some point during its execution.

This method is called regardless of whether your code performs one-step or two-step rotations.

Source - UIKit Framework Reference (hope this helpful to you)

Vineet Choudhary
  • 7,433
  • 4
  • 45
  • 72