亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

有沒有辦法在iPhone上通過觸摸?

有沒有辦法在iPhone上通過觸摸?

慕慕森 2019-12-26 11:00:43
UIButton在主區域中點擊時,我使用幾個s來設置當前動作。我還想允許用戶從按鈕直接拖動到主要區域并執行相同的操作;本質上,在觸摸UIButton時應將touchesBegan和touchesMoved傳遞給主視圖,還應發送按鈕按下動作?,F在,我可以更改控件了。拖動出口將調用內部觸摸區域以設置控件,然后調用觸摸開始區域以開始主區域觸摸操作。但是,此時,touchesMoved和touchesEnded顯然沒有被調用,因為觸摸起源于UIButton。有沒有一種方法可以半忽略觸摸,以便將它們傳遞到主區域,還可以讓我先設置控件?
查看完整描述

3 回答

?
MMTTMM

TA貢獻1869條經驗 獲得超4個贊

在文檔中,查找“ 響應者對象”和“響應者鏈”


您可以通過轉發響應者鏈上的修飾來“共享”對象之間的修飾。您的UIButton有一個接收UITouch事件的響應器/控制器,我的猜測是,一旦它對返回的消息執行了正確的解釋-觸摸已被處理和處置。


蘋果公司建議這樣的事情(當然取決于觸摸的類型):


[self.nextResponder touchesBegan:touches withEvent:event];


而不是處理觸摸事件,而是將其傳遞出去。


子類UIButton:


MyButton.h


#import <Foundation/Foundation.h>


@interface MyButton : UIButton {


}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event ;


@end

我的按鈕


#import "MyButton.h"


@implementation MyButton


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  

    printf("MyButton touch Began\n");

    [self.nextResponder touchesBegan:touches withEvent:event]; 

}

@end


查看完整回答
反對 回復 2019-12-26
?
喵喔喔

TA貢獻1735條經驗 獲得超5個贊

我知道這個問題已經有兩年了(并且已經回答了),但是...


當我自己嘗試時,觸摸被轉發了,但是按鈕不再像按鈕那樣表現。我也將修飾傳遞給“超級”,現在一切都很好。


因此,對于可能偶然發現此問題的初學者,代碼應如下所示:


- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {  

    [super touchesBegan:touches withEvent:event];

    [self.nextResponder touchesBegan:touches withEvent:event]; 

}


查看完整回答
反對 回復 2019-12-26
?
臨摹微笑

TA貢獻1982條經驗 獲得超2個贊

也無需繼承!只需將其放在實現的頂層即可,然后再進行其他操作:


#pragma mark PassTouch


@interface UIButton (PassTouch)

@end


@implementation UIButton (PassTouch)

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

{

    [super touchesBegan:touches withEvent:event];

    [self.nextResponder touchesBegan:touches withEvent:event];

}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event

{

    [super touchesMoved:touches withEvent:event];

    [self.nextResponder touchesMoved:touches withEvent:event];

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event

{

    [super touchesEnded:touches withEvent:event];

    [self.nextResponder touchesEnded:touches withEvent:event];

}

- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

{

    [super touchesCancelled:touches withEvent:event];

    [self.nextResponder touchesCancelled:touches withEvent:event];

}

@end


查看完整回答
反對 回復 2019-12-26
  • 3 回答
  • 0 關注
  • 760 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號