美文网首页api-UI
UITouch对象详解

UITouch对象详解

作者: 浅_若清风 | 来源:发表于2018-05-22 13:47 被阅读0次

    概述

    ios中对UITouch对象的定义是表示在屏幕上发生的触摸的位置、大小、运动和力的物体

    触摸对象包含内容

    1、触摸发生的视图或窗口 

    2、触摸在视图或窗口中的位置 

    3、触碰的近似半径 

    4、触摸力(支持3D触控或苹果铅笔的设备)

    属性方法

    1、获取触摸的位置

    //返回坐标系中的当前位置

    - (CGPoint)locationInView:(nullable UIView *)view;

    //返回坐标系中的先前位置

    - (CGPoint)previousLocationInView:(nullable UIView *)view;

    // 触摸的视图

    @property(nullable,nonatomic,readonly,strong) UIView      *view;

    //触摸的原始窗口

    @property(nullable,nonatomic,readonly,strong) UIWindow       *window;

    //触摸的半径

    @property(nonatomic,readonly) CGFloat majorRadius NS_AVAILABLE_IOS(8_0);

    //触摸半径的公差

    @property(nonatomic,readonly) CGFloat majorRadiusTolerance  NS_AVAILABLE_IOS(8_0);

    //触摸可用时,返回触摸的精确位置

    - (CGPoint)preciseLocationInView:(nullable UIView *)view NS_AVAILABLE_IOS(9_1);

    //触摸可用时,返回触控的精确先前位置

    - (CGPoint)precisePreviousLocationInView:(nullable UIView *)view NS_AVAILABLE_IOS(9_1);

    2、触摸属性

    //触摸的次数

    @property(nonatomic,readonly) NSUInteger          tapCount;

    //触摸发生的时间

    @property(nonatomic,readonly) NSTimeInterval      timestamp;

    //触摸的类型

    @property(nonatomic,readonly) UITouchType         type NS_AVAILABLE_IOS(9_0);

    //触摸的类型

    typedef NS_ENUM(NSInteger, UITouchType) {   

    //手指直接接触屏幕的触摸

    UITouchTypeDirect,      

    //间接接触的触摸           

    UITouchTypeIndirect,        

    //触笔触摸

    UITouchTypeStylus NS_AVAILABLE_IOS(9_1), 

    } NS_ENUM_AVAILABLE_IOS(9_0);

    //触摸的阶段

    @property(nonatomic,readonly) UITouchPhase        phase;

    //触摸的阶段

    typedef NS_ENUM(NSInteger, UITouchPhase) {   

    //手指触及屏幕

    UITouchPhaseBegan,   

    //手指在屏幕上移动时

    UITouchPhaseMoved,       

    //手指触摸屏幕但不移动

    UITouchPhaseStationary,      

    //手指离开屏幕

    UITouchPhaseEnded,            

    //触摸没有结束,但停止跟踪

    UITouchPhaseCancelled,        

    };

    //触摸的力度,其中1的值代表平均触摸的力(由系统预先确定,而不是用户特定)

    @property(nonatomic,readonly) CGFloat force NS_AVAILABLE_IOS(9_0);

    //触碰的最大可能力

    @property(nonatomic,readonly) CGFloat maximumPossibleForce NS_AVAILABLE_IOS(9_0);

    //触笔的高度(弧度)

    @property(nonatomic,readonly) CGFloat altitudeAngle NS_AVAILABLE_IOS(9_1);

    //返回手触笔的方位角(弧度)

    - (CGFloat)azimuthAngleInView:(nullable UIView *)view NS_AVAILABLE_IOS(9_1);

    //返回指向指针的方位角的单位向量

    - (CGVector)azimuthUnitVectorInView:(nullable UIView *)view NS_AVAILABLE_IOS(9_1);

    3、管理触摸属性

    //一组触控属性,其值仅包含估计值

    @property(nonatomic,readonly) UITouchProperties  estimatedProperties NS_AVAILABLE_IOS(9_1);

    //未来预期更新值的触控属性集

    @property(nonatomic,readonly) UITouchProperties estimatedPropertiesExpectingUpdates NS_AVAILABLE_IOS(9_1);

    //触摸属性的掩码

    typedef NS_OPTIONS(NSInteger, UITouchProperties) {   

    //力的触摸特性

    UITouchPropertyForce = (1UL << 0),    

    //方位角的触摸特性

    UITouchPropertyAzimuth = (1UL << 1),   

    //高度的触摸属性

    UITouchPropertyAltitude = (1UL << 2),   

    //位置的触摸属性

    UITouchPropertyLocation = (1UL << 3),

    } NS_AVAILABLE_IOS(9_1);

    //一个索引号码,让你把一个更新的触摸与原来的触摸联系起来。

    @property(nonatomic,readonly) NSNumber * _Nullable estimationUpdateIndex NS_AVAILABLE_IOS(9_1);

    4、获取触摸物体的手势识别器

    @property(nullable,nonatomic,readonly,copy)   NSArray *gestureRecognizers NS_AVAILABLE_IOS(3_2);

    5、压力感应

    typedef NS_ENUM(NSInteger, UIForceTouchCapability) {    

    //不确定是否支持压力感应

    UIForceTouchCapabilityUnknown = 0,    

    //不支持压力感应

    UIForceTouchCapabilityUnavailable = 1,   

    //支持压力感应

    UIForceTouchCapabilityAvailable = 2

    };

    相关文章

      网友评论

        本文标题:UITouch对象详解

        本文链接:https://www.haomeiwen.com/subject/ajhbdftx.html