UI手势回顾

UIGestureRecongnizer手势识别器

手势:有规律的触摸

UIGestureRecognizer抽象类

七种手势:轻拍(tap)长按(longPress)旋转(ritation)捏合(pinch)拖拽(pan)清扫(swipe)屏幕边缘拖拽(screenEdgePan)

UIImageView*imgView = [[UIImageViewalloc]initWithFrame:CGRectMake(0,0,200,200)];

imgView.center=self.view.center;

imgView.image= [UIImageimageNamed:@"qq.jpg"];

[self.viewaddSubview:imgView];

[imgViewrelease];

打开用户交互

imgView.userInteractionEnabled=YES;

轻拍

创建对象

获取到轻拍手势让self调用tapActiion:方法

UITapGestureRecognizer*tap =[[UITapGestureRecognizeralloc]initWithTarget:selfaction:@selector(tapAction:)];

添加手势

[imgViewaddGestureRecognizer:tap];

内存管理

[taprelease];

点击次数

tap.numberOfTapsRequired=2;

点击手指个数

tap.numberOfTouchesRequired=2;

长按longPress

UILongPressGestureRecognizer*press = [[UILongPressGestureRecognizeralloc]initWithTarget:selfaction:@selector(pressAction:)];

[imgViewaddGestureRecognizer:press];

[pressrelease];

长按时间

press.minimumPressDuration=1;

旋转rotation

UIRotationGestureRecognizer*rotation = [[UIRotationGestureRecognizeralloc]initWithTarget:selfaction:@selector(rotationAction:)];

[imgViewaddGestureRecognizer:rotation];

[rotationrelease];

捏合pinch

UIPinchGestureRecognizer*pinch = [[UIPinchGestureRecognizeralloc]initWithTarget:selfaction:@selector(pinchAction:)];

[imgViewaddGestureRecognizer:pinch];

[pinchrelease];

缩放scale

}

#pragma mark -轻拍

-(void)tapAction:(UITapGestureRecognizer*)tap{

NSLog(@"轻拍");

}

//#pragam mark -长按

-(void)pressAction:(UILongPressGestureRecognizer*)press{

长安手势是很多手势的基础

if(press.state==UIGestureRecognizerStateBegan){

NSLog(@"长按");

}

}

-(void)pinchAction:(UIPinchGestureRecognizer*)pinch{

//获取view

UIImageView*imgView = (UIImageView*)pinch.view;

缩放比例

imgView.transform=CGAffineTransformScale(imgView.transform, pinch.scale, pinch.scale);

pinch.scale=1;

NSLog(@"捏合");

}

你可能感兴趣的:(UI手势回顾)