當按鈕超過了父視圖範圍,點擊是沒有反應的。由於消息的傳遞是從最下層的父視圖開始調用hittest方法code
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *view = [super hitTest:point withEvent:event]; return view; }
須要重寫這個方法it
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { UIView *view = [super hitTest:point withEvent:event]; if (view == nil) { CGPoint tempoint = [btn convertPoint:point fromView:self]; if (CGRectContainsPoint(btn.bounds, tempoint)) { view = btn; } } return view; }