码迷,mamicode.com
首页 > 移动开发 > 详细

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

时间:2019-01-03 19:41:51      阅读:228      评论:0      收藏:0      [点我收藏+]

标签:color   rop   else   atomic   ble   encoding   nbsp   elf   get   

一、检测捏合手势( 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 = 1;
    singleTap.numberOfTouchesRequired = 1;
    [self.viewaddGestureRecognizer:singleTap];
   
    UITapGestureRecognizer *doubleTap =
    [[UITapGestureRecognizeralloc] initWithTarget:self
                                            action:@selector(tap2)];
    doubleTap.numberOfTapsRequired = 2;
    doubleTap.numberOfTouchesRequired = 1;
    [self.viewaddGestureRecognizer:doubleTap];
    [singleTap requireGestureRecognizerToFail:doubleTap];   //这句是最主要的
   
    UITapGestureRecognizer *tripleTap =
    [[UITapGestureRecognizeralloc] initWithTarget:self
                                            action:@selector(tap3)];
    tripleTap.numberOfTapsRequired = 3;
    tripleTap.numberOfTouchesRequired = 1;
    [self.viewaddGestureRecognizer:tripleTap];
    [doubleTap requireGestureRecognizerToFail:tripleTap];
   
    UITapGestureRecognizer *quadrupleTap =
    [[UITapGestureRecognizeralloc] initWithTarget:self
                                            action:@selector(tap4)];
    quadrupleTap.numberOfTapsRequired = 4;
    quadrupleTap.numberOfTouchesRequired = 1;
    [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 = @"";
}

 

 
 

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

标签:color   rop   else   atomic   ble   encoding   nbsp   elf   get   

原文地址:https://www.cnblogs.com/ios-wmm/p/10215963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!