/
触摸开始时调用
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);// 打印方法
}
// 触摸进行时调用
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
}
// 触摸结束时调用
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
}
// 触摸被打断时调用,比如 有电话过来
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
// 触摸进行时调用
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
}
// 触摸结束时调用
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
}
// 触摸被打断时调用,比如 有电话过来
-(void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"%s",__func__);
}
NSArray
集合
有序
NSSet
集合
无序
touch.phase
touchs.count 枚举类型
触摸事件是从父控件传递到子控件:UIApplication ->UIWindow ->父控件->子控件
如果父控件不接受触摸事件,那么子控件也不会接收到触摸事件。注意:不是没人处理,而是由能穿到的最后一级处理
控件接收不到触摸事件的原因:
1、不接受用户交互 userIteractionEnabled = NO;
2、 隐藏 hidden = YES;
3、 透明 alpha = 0.0~0.01;
注意:UIImageVIew的userIteractionEnabled默认是NO
手势:
每一个手势识别器的用法都差不多,比如UITapGestureRecognizer的使用步骤如下
创建手势识别器对象
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init];
设置手势识别器对象的具体属性
// 连续敲击2次
tap.numberOfTapsRequired = 2;
// 需要2根手指一起敲击
tap.numberOfTouchesRequired = 2;
添加手势识别器到对应的view上
[self.iconView addGestureRecognizer:tap];
监听手势的触发
[tap addTarget:self action:@selector(tapIconView:)];
为了完成手势识别,必须借助于手势识别器----UIGestureRecognizer
利用UIGestureRecognizer,能轻松识别用户在某个view上面做的一些常见手势
UIGestureRecognizer是一个抽象类,定义了所有手势的基本行为,使用它的子类才能处理具体的手势
UITapGestureRecognizer(敲击)
UIPinchGestureRecognizer(捏合,用于缩放)
UIPanGestureRecognizer(拖拽)
UISwipeGestureRecognizer(轻扫)
UIRotationGestureRecognizer(旋转)
UILongPressGestureRecognizer(长按)