在ios中如果按鈕的位置超出父視圖無法響應.如何處理?

來源:互聯網
上載者:User

標籤: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中如果按鈕的位置超出父視圖無法響應.如何處理?

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.