美文网首页
UITouch的方法

UITouch的方法

作者: 小小纳兰 | 来源:发表于2017-09-12 11:48 被阅读21次
  • 在触摸开始时,调用 这个方法
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesBegan");
    
    //手指在屏幕上每一次触摸都会产生一个触摸事件
    //这些事件会保存这个NSSet 类型的 touches里
    //我们可以取出这个事件
    UITouch * touch = [touches anyObject];
    [UIView animateWithDuration:0.3 animations:^{
        imageView.center = [touch locationInView:self.window];
    }];
    
    
    NSLog(@"window:%@",touch.window);
    NSLog(@"view:%@",touch.view);
    NSLog(@"phase:%id",touch.phase);
}

  • 手指离开屏幕时,触发这个方法
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSLog(@"touchesEnded");
    //可以在这里不使用任何一个事件,只去写我们自己的方法

    [UIView animateWithDuration:0.3 animations:^{
        imageView.center = CGPointMake(160, 300);
    }];
    
}
  • 手指在屏幕上移动时,触发这个方法
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
    //那么,手指只要在屏幕有偏移那么就调用一次这个方法
    NSLog(@"touchesMove");
    UITouch * touch = [touches anyObject];
    NSLog(@"view:%@",touch.view);
    if (touch.view == imageView && touch.phase == UITouchPhaseMoved) {
        imageView.center = [touch locationInView:self.window];
 }
  • 触摸被打断时调用的方法
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
    //程序运行过程中,进来电话,短信,推送等优先级比较高的事件
}

相关文章

  • UITouch

    1:触摸事件 2:加速计事件 3:远程控制事件 UITouch UITouch的属性 UITouch的方法 UIE...

  • UITouch的方法

    在触摸开始时,调用 这个方法 手指离开屏幕时,触发这个方法 手指在屏幕上移动时,触发这个方法 触摸被打断时调用的方法

  • UI:触摸与手势

    触摸(UITouch) UITouch方法 场景举例有时需要用户触摸某个视图移动,并且视图会跟着触摸手势轨迹的移动...

  • iOS触摸事件详解

    目录:1 UITouch1.1 UITouch的创建1.2 UITouch的作用1.3 UITouch的常用属性1...

  • iOS_UITouch 事件

    UITouch 基本事件函数 UITouch 包含如下四个基本函数,touches 集合中存储的事UITouch ...

  • IOS开发 UITouch

    本节学习内容: 1.UITouch的基本概念 2.UITouch的作用周期 3.UITouch的应用 【viewC...

  • UIView的Touch事件

    处理事件的方法 UIView是UIResponder的子类,可以覆盖下列4个方法处理不同的触摸事件 UITouch...

  • iOS UITouch

    UITouch UITouch的属性 触摸产生时所处的窗口 @property(nonatomic,readonl...

  • 触摸事件

    响应者对象 UIResponder UIView的触摸事件处理 UITouch UITouch的属性 UITouc...

  • UITouch

    UITouch对象是一个手指接触到屏幕并在屏幕上移动或离开屏幕时创建的。 处理原理 当用户点击屏幕时,会产生一个触...

网友评论

      本文标题:UITouch的方法

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