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

  • 相关阅读:
    es学习-java操作 2.4.0版本
    es学习-基础增删改查
    mongodb 查询条件
    mongodb-查询
    mysql 性能优化
    mysql 存储过程学习(总)
    MySQL 存储过程 -流程控制的使用
    MySQL 存储过程 -光标的使用
    maven的聚合和继承
    mavean的依赖传递和排除依赖
  • 原文地址:https://www.cnblogs.com/haibosoft/p/4178669.html
Copyright © 2011-2022 走看看