zoukankan      html  css  js  c++  java
  • IOS 特定于设备的开发:处理基本方向

    UIDevice类使用内置的orientation属性获取设备的物理方向。IOS设备支持这个属性的7个可能的值。

        》UIDeviceOrientationUnknown:方向目前未知。

        》UIDeviceOrientationPortrait:Home键在下。

        》UIDeviceOrientationPortraitUpsideDown:Home键在上

        》UIDeviceOrientationLandscapeLeft:Home键在左边

        》UIDeviceOrientationLandscapeRight:Home键在右边

        》UIDeviceOrientationFaceUp:设备正面朝上

        》UIDeviceOrientationFaceDown:设备正面朝下

    IOS 提供了两个内置宏,帮组确定设备方向枚举值是纵向还是横向的:既UIDeviceOrientationIsPortrait()和UIDeviceOrientationIsLandscape().能够很方便的扩展UIDevice类,提供这些测试作为内置的设备属性。

    在UIDevice扩展类中添加如下代码

    @property (nonatomic , readonly)BOOL isLandscape;
    @property (nonatomic , readonly)BOOL isPortrait;
    -(BOOL)isLandscape
    {
        return UIDeviceOrientationIsLandscape([UIDevice currentDevice].orientation);
    }
    
    -(BOOL)isPortrait
    {
        return UIDeviceOrientationIsPortrait([UIDevice currentDevice].orientation);
    }

    代码也可以直接订阅设备重定向通知。为此,可以把beginGeneratingDeviceOrientationNotification发送给currentDevice单例。然后添加一个观察者,捕获随后发生的UIDeviceOrientationDidChangeNotification更新。如你所期望的,可以通过调用UIDeviceOrientationDidChangeNotificationOrientationNotification来完成侦听。

  • 相关阅读:
    bzoj1053(反素数)
    poj1442(对顶堆)
    poj2823(单调队列)
    poj3630(简单tire)
    poj1924(单调栈求最大矩阵)
    最大xor路径(poj3764)
    poj2689
    求n!末尾0的个数
    BigInteger和BigDecimal的基本用法
    大数乘法
  • 原文地址:https://www.cnblogs.com/haibosoft/p/4178669.html
Copyright © 2011-2022 走看看