博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
触发事件续
阅读量:6948 次
发布时间:2019-06-27

本文共 1645 字,大约阅读时间需要 5 分钟。

Main.storyboard

CZView.h

#import <UIKit/UIKit.h>

 

@interface CZView : UIView

 

@end

CZView.m

//

//  CZView.m

//  6A05.触摸事件

//

//  Created by huan on 16/1/30.

//  Copyright © 2016 huanxi. All rights reserved.

//

 

#import "CZView.h"

 

@implementation CZView

 

/*

// Only override drawRect: if you perform custom drawing.

// An empty implementation adversely affects performance during animation.

- (void)drawRect:(CGRect)rect {

    // Drawing code

}

*/

 

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

    return;

    NSLog(@"%s", __func__);

    //获取当前触摸点的UITouch对象

    UITouch *touch = [touches anyObject];

    //触摸的view

    NSLog(@"%@", touch.view);

    

    //tapCount 点击的次数

    NSLog(@"%ld", touch.tapCount);

    

    //获取当前 触摸的位置

#warning 传一个nil 获取的触摸点的位置是在window上去  self = touch.view

    CGPoint touchPosition = [touch locationInView:self];

    NSLog(@"%@", NSStringFromCGPoint(touchPosition));

}

 

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

    NSLog(@"%s", __func__);

    //获取当前触摸点的UITouch对象

    UITouch *touch = [touches anyObject];

    //获取当前触摸的位置

    CGPoint current = [touch locationInView:touch.view];

    //获取触摸前的位置

    CGPoint previous = [touch previousLocationInView:touch.view];

    NSLog(@"触摸前的点:%@ 当前触摸点:%@", NSStringFromCGPoint(previous), NSStringFromCGPoint(current));

    //改变位置

    CGPoint center = self.center;

    center.x += current.x - previous.x;

    center.y += current.y - previous.y;

    self.center = center;

}

 

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

    NSLog(@"%s", __func__);

}

 

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

    NSLog(@"%s", __func__);

}

 

@end

转载于:https://www.cnblogs.com/Lu2015-10-03/p/5178373.html

你可能感兴趣的文章
HTML——CSS3学习
查看>>
亚像素级角点定位
查看>>
C#闭包函数
查看>>
浅谈vr基础视频教程 改变技术革命
查看>>
c++调用DOS命令,不显示黑屏
查看>>
$apply()和$digest()——angular
查看>>
如何解决GitHub冲突<一>:GitHubDesktop同步你的分支
查看>>
python虚拟环境
查看>>
ls -l 各项含义
查看>>
Helios与Katana的区别
查看>>
远程连接Mysql失败的问题的解决的原因
查看>>
师生关系读后感
查看>>
多线程初步学习
查看>>
一道关于https进行登录验证的前端面试题
查看>>
django server之间通过remote user 相互调用
查看>>
HDU 1011 Starship Troopers【树形DP】
查看>>
单行多行点点点
查看>>
Java 泛型 <? super T> 中 super 怎么 理解?与 < ? extends T>有何不同?
查看>>
类的特性-封装
查看>>
SQL练习1关于插入删除,修改,单表查询
查看>>