有没有一种方法可以轻松检测到最近的UIButton到一个水龙头位置?我目前已经划分了一个平底锅手势,但在解决如何解决这个问题时遇到了困难。在过去,我调整了每个按钮的框架大小,以便在按钮之间没有空白区域,但在我目前的情况下这是不可能的。有没有办法检测最近的UIButton来点击位置?
目前,我已经成功地通过了我的子视图,并可以检测到我/不在按钮顶部。但是当我不在按钮上时,如何检测最接近的按钮?
谢谢!
这里是我的代码,用于识别我的UIButtons:
- (UIView *)identifySubview:(NSSet *)touches {
CGPoint tapLocation = [[touches anyObject] locationInView:self.view];
for (UIView *view in [self.view viewWithTag:1000].subviews) {
for (UITableViewCell *cell in view.subviews) {
for (UIView *contentView in cell.subviews) {
for (UIButton *button in contentView.subviews) {
if ([button isKindOfClass:[UIButton class]]) {
CGRect trueBounds = [button convertRect:button.bounds toView:self.view];
if (CGRectContainsPoint(trueBounds, tapLocation)) {
return button;
} else {
//How would I detect the closest button?
}
}
}
}
}
}
return nil;
}
按钮都是相同的大小? – 2014-11-06 03:28:49