簡體   English   中英

將滾動事件從uibutton傳遞到uiscrollview

[英]pass scroll event from uibutton to uiscrollview

我有水平UIScrollView ,從UIScrollView擴展,我水平添加UIButtons 我只能滾出按鈕區域,但如果我想滾動任何按鈕,則會觸發UIControlEventTouchUpInside事件。 我不想要這個。 我想點擊UIControlEventTouchUpInside動作,如果我點擊,我想滾動,如果我滾動。

那么如何將滾動事件從UIButton傳遞到UIScrollView

子類UIScrollView,在- touchesShouldCancelInContentView:方法中返回YES。

該功能已經內置。當您將UIControl元素作為滾動視圖的子視圖並檢測到觸摸事件時,它最初會傳遞給UIScrollView。 如果在一兩秒之后觸摸事件中沒有足夠的移動,它會被傳遞到按鈕。

試試這個:

self.button.exclusiveTouch = YES

對我來說就像一個魅力!

如果您繼承NSButton並創建該類型的按鈕並覆蓋子類中的以下內容,則可以將事件傳遞回父視圖,在您的情況下滾動視圖

以下將使按鈕永遠不會觸發事件,而是所有將由父視圖處理:

- (void)touchesBegan: (NSSet *)touches withEvent:(UIEvent *)event {
    [self.nextResponder touchesBegan:touches withEvent:event];      
}

- (void)touchesMoved: (NSSet *)touches withEvent:(UIEvent *)event {
    [self.nextResponder touchesMoved:touches withEvent:event];  
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent*)event 
{
    [self.nextResponder touchesEnded:touches withEvent:event];  
}

如果你想讓按鈕處理其中一個事件而不是使用

[super touchesEnded:touches withEvent:event];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM