iOS 轻击、触摸和手势的检测

一、检测捏合手势( UIPinchGestureRecognizer): 
//设定一个实例变量存储手指之间的其起始距离
@property (assign, nonatomic) CGFloat initialFontSize; //调用:
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizeralloc]
initWithTarget:selfaction:@selector(doPinch:)];
[self.viewaddGestureRecognizer:pinch]; //实现方法:
- (void)doPinch:(UIPinchGestureRecognizer *)pinch {
if (pinch.state == UIGestureRecognizerStateBegan) {
initialFontSize = label.font.pointSize;//开始时的
} else {
label.font = [label.fontfontWithSize:initialFontSize * pinch.scale];
}
}
 
 
 
二、 检测多次轻击(UITapGestureRecognizer):
//调用:
UITapGestureRecognizer *singleTap =
[[UITapGestureRecognizeralloc] initWithTarget:self
action:@selector(tap1)];
singleTap.numberOfTapsRequired = ;
singleTap.numberOfTouchesRequired = ;
[self.viewaddGestureRecognizer:singleTap]; UITapGestureRecognizer *doubleTap =
[[UITapGestureRecognizeralloc] initWithTarget:self
action:@selector(tap2)];
doubleTap.numberOfTapsRequired = ;
doubleTap.numberOfTouchesRequired = ;
[self.viewaddGestureRecognizer:doubleTap];
[singleTap requireGestureRecognizerToFail:doubleTap]; //这句是最主要的 UITapGestureRecognizer *tripleTap =
[[UITapGestureRecognizeralloc] initWithTarget:self
action:@selector(tap3)];
tripleTap.numberOfTapsRequired = ;
tripleTap.numberOfTouchesRequired = ;
[self.viewaddGestureRecognizer:tripleTap];
[doubleTap requireGestureRecognizerToFail:tripleTap]; UITapGestureRecognizer *quadrupleTap =
[[UITapGestureRecognizeralloc] initWithTarget:self
action:@selector(tap4)];
quadrupleTap.numberOfTapsRequired = ;
quadrupleTap.numberOfTouchesRequired = ;
[self.viewaddGestureRecognizer:quadrupleTap];
[tripleTap requireGestureRecognizerToFail:quadrupleTap]; //不同点击触发的事件:
- (void)tap1 {
singleLabel.text = @"Single Tap Detected";
[selfperformSelector:@selector(eraseMe:)
withObject:singleLabelafterDelay:1.6f];
}
- (void)tap2 {
doubleLabel.text = @"Double Tap Detected";
[selfperformSelector:@selector(eraseMe:)
withObject:doubleLabelafterDelay:1.6f];
}
- (void)tap3 {
tripleLabel.text = @"Triple Tap Detected";
[selfperformSelector:@selector(eraseMe:)
withObject:tripleLabelafterDelay:1.6f];
}
- (void)tap4 {
quadrupleLabel.text = @"Quadruple Tap Detected";
[selfperformSelector:@selector(eraseMe:)
withObject:quadrupleLabelafterDelay:1.6f];
} //清除内容
- (void)eraseMe:(UILabel *)label {
label.text = @"";
}
 
 
上一篇:HttpClient Received an unexpected EOF or 0 bytes from the transport stream


下一篇:Android ScrollView