The Uidevice class uses the built-in orientation property to get the physical direction of the device. iOS devices support 7 possible values for this property.
"Uideviceorientationunknown: The direction is unknown.
"uideviceorientationportrait: The Home key is under."
"Uideviceorientationportraitupsidedown: Home key on top
"Uideviceorientationlandscapeleft: Home key on the left
"Uideviceorientationlandscaperight: The Home key is on the right
"Uideviceorientationfaceup: the equipment faces up
"Uideviceorientationfacedown: the equipment faces down
IOS provides two built-in macros that help the group determine whether the device orientation enumeration values are portrait or landscape: both uideviceorientationisportrait () and Uideviceorientationislandscape (). It is convenient to extend the Uidevice class to provide these tests as built-in device properties.
Add the following code to the Uidevice extension class
ReadOnlyreadonly) BOOL isportrait;
-(BOOL) islandscape{ return uideviceorientationislandscape ([Uidevice Currentdevice]. orientation);} -(BOOL) isportrait{ return uideviceorientationisportrait ([Uidevice Currentdevice]. orientation);}
The code can also subscribe to device redirection notifications directly. To this end, the begingeneratingdeviceorientationnotification can be sent to Currentdevice single case. Then add an observer to capture the Uideviceorientationdidchangenotification update that occurs later. As you might expect, you can listen by calling Uideviceorientationdidchangenotificationorientationnotification.
Device-specific development for IOS: handling Basic Directions