iPhone:具有多个响应水龙头的区域的自定义UITableViewCell? [英] iPhone: Custom UITableViewCell with multiple areas that respond to taps?
问题描述
我被要求创建一个具有多个可以点击的区域的自定义UITableViewCell.
I've been asked to create a custom UITableViewCell with multiple areas that can be tapped.
这些区域将没有按钮或任何图形-它们将是不可见的.根据用户点击的单元格的哪三分之一(即
These areas won't have buttons or any graphics - they'll be invisible. 3 different methods will be called depending on which third of the cell the user taps i.e.
||decrementFooCount ||viewFooDetails ||crementFooCount ||
|| decrementFooCount || viewFooDetails || incrementFooCount ||
该单元格上有一些需要始终可见的标签-fooName和fooCount.
The cell has a few labels on it that need to be visible at all times - the fooName and fooCount.
我在想单元格上可能有三个隐藏的UIButton?
I'm thinking perhaps three hidden UIButtons over the cell?
我还需要保持滑动以删除默认行为.
I also need to maintain the swipe to delete default behavior.
推荐答案
您可以将UITableViewCell子类化,并覆盖 touchesBegan:withEvent:
方法.然后,您可以获取触摸位置的CGPoint.
You can subclass your UITableViewCell and override the touchesBegan:withEvent:
method. You can then get a CGPoint of where the touch was placed.
- (void)touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch* touch = touches.anyObject;
CGPoint location = [touch locationInView:self];
if (CGRectContainsPoint(myTestRect, location)) {
// Touched inside myTestRect, do whatever...
} else {
// Let the default implementation take over.
[super touchesBegan:touches withEvent:event];
}
}
安德鲁
这篇关于iPhone:具有多个响应水龙头的区域的自定义UITableViewCell?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!