[英]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.