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来完成侦听。

  • 相关阅读:
    天梯赛练习2 补题
    QFNU 天梯赛练习 1 补题
    2019 山东省赛 B 题
    CCPC2020 网络赛 总结
    一个比较好看的 Typora 主题
    〔OS〕磁盘调度算法
    〔OS〕页面置换算法
    〔OS〕多线程模拟实现生产者和消费者
    〔OS〕银行家算法
    LCS and LIS
  • 原文地址:https://www.cnblogs.com/haibosoft/p/4178669.html
Copyright © 2011-2022 走看看