星空网 > 软件开发 > 操作系统

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:%@ \n viewB:%@ \n 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:%@ \n view:%@ \n window:%@",touctObj,[touctObj view],[touctObj window]);

}


 

UITouch详解images/loading.gif' data-original="http://images2015.cnblogs.com/blog/133128/201512/133128-20151217153120115-145126962.png" />UITouch详解

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

 

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

 




原标题:UITouch详解

关键词:

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流