<span style="background-color: rgb(153, 153, 255);">//
// UIGestureViewController.m
// LJEExcise
//
// Created by xiaoyao on 14/11/29.
// Copyright (c) 2014年 lijien. All rights reserved.
//
#import "UIGestureViewController.h"
#define kLABELFRAME (CGRectMake(20, 150, 200, 50))
#define kVIEWFRAME (CGRectMake(20, 220, 200, 80))
@interface UIGestureViewController () {
UILabel *_touchLabel;
UIView *_touchView;
}
@end
@implementation UIGestureViewController
- (void)viewDidLoad {
[super viewDidLoad];
_touchLabel = [[UILabel alloc] initWithFrame:kLABELFRAME];
_touchLabel.backgroundColor = [UIColor blueColor];
_touchLabel.tag = 9999;
_touchLabel.textColor = [UIColor redColor];
// 当UI控件不允许用户使用交互属性的时候应当打开其交互
_touchLabel.userInteractionEnabled = YES;
// 是否支持多点触碰
_touchLabel.multipleTouchEnabled = YES;
[self.view addSubview:_touchLabel];
_touchView = [[UIView alloc] initWithFrame:kVIEWFRAME];
_touchView.backgroundColor = [UIColor purpleColor];
[self.view addSubview:_touchView];
for (int i = 1; i < 6; i++) {
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(handleTap:)];
// 连续点击的次数
tap.numberOfTapsRequired = i;
// 允许两个手指的触碰
tap.numberOfTouchesRequired = 1;
[_touchView addGestureRecognizer:tap];
}
}
- (void)handleTap:(UITapGestureRecognizer *)tap {
// 用户的第几个手指触碰
NSUInteger touchNum = tap.numberOfTouches;
NSUInteger tapNum = tap.numberOfTapsRequired;
_touchLabel.text = [NSString stringWithFormat:@"tapNum: %lu touchNum: %lu",tapNum, touchNum];
[_touchLabel performSelector:@selector(setText:) withObject:nil afterDelay:2];
}
- (void)setText:(UILabel *)label {
[_touchLabel setText:@"aaa"];
return;
}
@end
</span>
点击手势demo
最新推荐文章于 2021-05-29 01:24:45 发布