I have a question on how to detect the device orientation on iOS. I don't need to receive change notifications, just the current orientation itself. This seems to be a rather simple question, but I haven't been able to wrap my head around it. Below is what I have done so far:
UIDevice *myDevice = [UIDevice currentDevice] ;
[myDevice beginGeneratingDeviceOrientationNotifications];
UIDeviceOrientation deviceOrientation = myDevice.orientation;
BOOL isCurrentlyLandscapeView = UIDeviceOrientationIsLandscape(deviceOrientation);
[myDevice endGeneratingDeviceOrientationNotifications];
In my mind this should work. I enable the device to receive device orientation notices, then ask for what orientation it is in, but then it is not working and I don't know why.
Have you unlocked the hardware lock for device orientation? There is one at the edge of my iPad 1.
Really old thread, but no real solution.
I Had the same problem, but found out that getting The UIDeviceOrientation isn't always consistent, so instead use this:
if UIViewController:
if UIView:
UIDevice.h:
Updated:
add this code to xxx-Prefix.pch then you can use it anywhere:
usage:
For what You looking for first you have to Get Notification if Orientation Changed! You Can set This Thing in viewDidLoad like
and whenever Orientation of your Device changed OrientationDidChange Called where You can do whatever You Want as Per Orientation