0

I am have a custom CALayer which should look different with respect to different interface orientation. Is there a way that I can access the interfaceOrientation of the View Controller where I am using this CALayer ?

Or I will have to set a property in the custom Layer indicating the current orientation every time it changes ?

Amogh Talpallikar
  • 12,084
  • 13
  • 79
  • 135

2 Answers2

1

You could set a property on the custom layer.

Or you could give the custom layer a property that references the view controller so it can just ask the view controller for the interface orientation when the layer needs to know.

Or you could have your view controller post an NSNotification when it rotates, and have the layer observe the notification.

rob mayoff
  • 375,296
  • 67
  • 796
  • 848
0
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];

returns UIInterfaceOrientation, current orientation of the application's status bar.


UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation]; returns UIDeviceOrientation, device orientation. But note that UIDeviceOrientation is not always UIInterfaceOrientation. For example, when your device is on a plain table you can receive unexpected value.

beryllium
  • 29,669
  • 15
  • 106
  • 125