恐怕用 imageview 作为按钮是错误的,但如果你坚持这样做,试试这些:
您可以通过子类化 imageview 来重写 hitTest 方法
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
UIView *hittedView = [super hitTest: point withEvent: event];
NSLog (@"self=<%p>, hitted=<%p>", self, hittedView);
return hittedView;
}
添加日志以查看默认的 hitTest 是否返回正确的子视图。
如果没有,恐怕您必须自己编写 hitTest 代码:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
{
for (UIView *view in self.subviews) {
if (CGRectContainsPoint(view.frame, point)) {
return view;
}
}
return self
}
本文档对您很有用:http:
//developer.apple.com/library/ios/#documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/Introduction/Introduction.html