zoukankan      html  css  js  c++  java
  • iOS中文API之UITouch详解

      UITouch 对象用于位置、 大小、 运动和一根手指在屏幕上为某一特定事件的力度。触摸的力度是从开始在 iOS 9 支持 3D 的触摸的设备上可用。你可以通过UIEvent对象传递给响应者对象访问。一个UITouch对象包括访问器:

      引起触摸的视图或Window.

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

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

      触摸在视图或Window的位置坐标.

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

      触摸的半径.

    @property(nonatomic,readonly) CGFloat altitudeAngle

      触摸的力度(支持iOS9.0以上)

    @property(nonatomic,readonly) CGFloat force

      UITouch对象还包含一个指示触摸发生时间的时间戳,一个整数表示用户点击屏幕的次数,在触摸阶段以常量的形式描述触摸是否开始,移动,或结束,或者是否为系统取消触摸。
      一个触摸对象始终存留一个触摸序列。处理事件时,永远不会保留一个触摸对象。如果你需要从一个触摸阶段到另一个阶段保留有关触摸信息,就应该复制该信息。
      触摸的 gestureRecognizers 属性包含当前正在处理的触摸手势识别器。每个手势识别器是 UIGestureRecognizer 具体子类的一个实例。

      下面是一个实例

    我在ViewController定义2个UIVIEW实例对象

    @interface ViewController : UIViewController
    
    @property (nonatomic, strong) UIView *viewA;
    @property (nonatomic, strong) UIView *viewB;
    
    @end

    然后

    - (void)viewDidLoad {

        [super viewDidLoad];

        // Do any additional setup after loading the view, typically from a nib.

        

        self.viewA =[[UIView alloc] initWithFrame:CGRectMake(10, 30, 48, 48)];

        self.viewA.backgroundColor  = [UIColor blackColor];

        [self.view addSubview:self.viewA];

        

        self.viewB =[[UIView alloc] initWithFrame:CGRectMake(10, 100, 48, 48)];

        self.viewB.backgroundColor  = [UIColor redColor];

        [self.view addSubview:self.viewB];

        

        NSLog(@"viewA:%@ viewB:%@ window:%@",self.viewA,self.viewB,[[[UIApplication sharedApplication] windows] objectAtIndex:0]);

    }

    - (void)didReceiveMemoryWarning {

        [super didReceiveMemoryWarning];

        // Dispose of any resources that can be recreated.

    }

    - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

    {

    //    NSLog(@"%@",[touches anyObject]);

        UITouch *touctObj = [touches anyObject];

        NSLog(@"touch:%@ view:%@ window:%@",touctObj,[touctObj view],[touctObj window]);

    }

    触摸以外区域我们可以看到view不是viewa也不是viewb,它是控制器的view.window是应用程序的window.

       总之,UITouch对象包含一些发生触摸的信息。引起触摸的视图或window。

  • 相关阅读:
    el-table单元格新增、编辑、删除功能
    div 拖拽
    dataTable 分页用法总结
    pc端字体大小计算以及echart中字体大小计算
    pc端字体大小自适应几种方法
    AB PLC教程
    Electric p8激活教程
    三菱FX系列PLC教程
    Visual Studio 2015简体中文企业版/专业版下载+有效激活密钥
    servlet在mvc里的分层,驻留内存的疑问?
  • 原文地址:https://www.cnblogs.com/salam/p/5054212.html
Copyright © 2011-2022 走看看