iOS开发,如何实现单击label可以让其移动到随机位置,双击label可以移动到想要的位置
展开全部
在label添加UITapGestureRecognizer 手势
UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)]; singleFingerOne.numberOfTouchesRequired = 1; //手指数 singleFingerOne.numberOfTapsRequired = 1; //tap次数
singleFingerOne.delegate = self;
[label addGestureRecognizer:singleFingerOne];
UITapGestureRecognizer *singleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)]; singleFingerTwo.numberOfTouchesRequired = 1;
singleFingerTwo.numberOfTapsRequired = 2;
singleFingerTwo.delegate = self;
[label addGestureRecognizer:singleFingerTwo];
[singleFingerOne requireGestureRecognizerToFail:singleFingerTwo];//加这句话是为了出发双击事件时不响应单击事件。
UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)]; singleFingerOne.numberOfTouchesRequired = 1; //手指数 singleFingerOne.numberOfTapsRequired = 1; //tap次数
singleFingerOne.delegate = self;
[label addGestureRecognizer:singleFingerOne];
UITapGestureRecognizer *singleFingerTwo = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleSingleFingerEvent:)]; singleFingerTwo.numberOfTouchesRequired = 1;
singleFingerTwo.numberOfTapsRequired = 2;
singleFingerTwo.delegate = self;
[label addGestureRecognizer:singleFingerTwo];
[singleFingerOne requireGestureRecognizerToFail:singleFingerTwo];//加这句话是为了出发双击事件时不响应单击事件。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询