標籤:view 情況 class llb detail 按鈕 無法 convert 根據
在按鈕所在的父視圖中重寫以下方法.
以下例子中我在父視圖外添加了二個按鈕callBtn和detailBtn;
以下例子應用情境為.高德地圖中的自訂泡泡視圖.因為泡泡視圖預設添加在圖釘視圖上.而一般情況下圖釘視圖的尺寸遠遠小於泡泡視圖導致泡泡視圖整個都在圖釘視圖外.無法響應點擊事件.
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *view = [super hitTest:point withEvent:event]; // 先按正常方法擷取響應事件的視圖
if (view == nil) {
CGPoint tempointcallBtn = [self.calloutView.callBtn convertPoint:point fromView:self]; // 將點擊的點座標轉換成我們想要響應的視圖的對應座標系中的座標.(座標系轉換)
CGPoint tempointdetailBtn = [self.calloutView.detailBtn convertPoint:point fromView:self]; // 如果要判斷多個按鈕,則根據此規則多次添加對應點.關在if語句後添加對應else if判斷.
if (CGRectContainsPoint(self.calloutView.callBtn.bounds, tempointcallBtn)) // 判斷當前點擊的位置是否在我們要響應的視圖中.
{
view = self.calloutView.callBtn; // 如果判斷為真則返回我們要響應的視圖.
} else if (CGRectContainsPoint(self.calloutView.detailBtn.bounds, tempointdetailBtn)) {
view = self.calloutView.detailBtn;
}
}
return view;
}
在ios中如果按鈕的位置超出父視圖無法響應.如何處理?