Device-specific development for IOS: handling Basic Directions

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.