問題所在:UIButton是某UIView的子視圖,但是UIButton超出了UIView的邊界,正常情況下點(diǎn)擊事件會(huì)失效。在該UIView下實(shí)現(xiàn)- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event就能解決此問題。代碼如下:
//其中detailBtn就是超出邊界的按鈕
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
? ? ? ? ?UIView *result = [super hitTest:point withEvent:event];
? ? ? ? ?CGPoint buttonPoint = [detailBtn convertPoint:point fromView:self];
? ? ? ? ?if ([detailBtn pointInside:buttonPoint withEvent:event]) {
? ? ? ? ? ? ? ? ? ?return detailBtn;
? ? ? ? ? }
? ? ? ? ? return result;
}