[英]Subclassed UIView but not getting touches
所以我有一個用IB制作的UIView。 然后,將該類設置為自定義UIView類,以便可以從該視圖獲取觸摸。 但是由於某種原因,我屏幕上的UIView不是我的自定義類。 我試過拋棄它:
myView = (CustomUIView *)myView;
我也嘗試過將其設置為CustomUIView:
myView = [[CustomUIView alloc] init];
(將對象添加到屏幕時,這會導致錯誤(我猜是因為我已經覆蓋了IBOutlet或其他東西。
那么,如何從該視圖獲取觸摸(觸摸開始,觸摸取消等)?
看看將UIGestureRecognizers添加到視圖中。
我認為這是您最好的選擇。
確保您的插座還符合標題中的新CustomUIView
類:
#import "CustomUIView.h"
.....
IBOutlet CustomUIView *myView;
您可以通過編程方式進行
CustomUIView *custom = [[CustomUIView alloc] initWithFrame:self.view.frame];
self.view = custom;
[custom release];
並在CustomUIView上實現UIResponder
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
}
大聲笑,我有一個以編程方式添加到customUIView的UIView,它填充了customUIView,阻止了任何觸摸。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.