所以我有一個用IB製作的UIView。我將該類設置爲我的自定義UIView類,以便我可以從該視圖獲得觸動。但出於某種原因,我屏幕上的UIView不是我的自定義類。我試圖鑄造它:Subclassed UIView,但沒有觸及
myView = (CustomUIView *)myView;
我也嘗試將其設置等於CustomUIView:
myView = [[CustomUIView alloc] init];
(這導致當我對象添加到屏幕中的錯誤(我猜這是因爲我已經覆蓋了IBOutlet中或東西。
所以,我怎麼能得到觸摸(觸摸開始,觸摸取消等),從這個觀點?
但我不需要手勢識別器,我需要觸摸。 – ManOx
GestureRecognizer爲您提供觸摸。 UITapGestureRecognizer會告訴你何時點擊視圖。 UIPanGestureRecognizer告訴你何時點擊視圖,觸摸移動,觸摸結束。手勢識別器是Apple提供的更新的首選解決方案(touchesBegan,Moved,並且仍然可以工作,但已經過時)。他們也比較容易理解,這就是我提出這個建議的原因。 – WendiKidd