[英]How can I get touchesBegan event on SuperView
In my program there is two views(scrollView-super, view-sub*2). 在我的程序中有两个视图(scrollView-super,view-sub * 2)。
In my case two subviews are subviewed in scrollView. 在我的情况下,两个子视图在scrollView中被子视图。 touchesBegan event called in subviews.
touchesBegan事件在子视图中调用。
How Can I get event in scrollView??? 如何在scrollView中获取事件???
@interface MyScrollView:UIScrollView
...
@implement MyScrollView
...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//here is my code
//but I can't get event here
...
}
-(id)initWithFrame:(CGRect) frame
{
...
MyView *view1 = [[MyView alloc] initWithFrame:(0, 0, 320, 240);
MyView *view2 = [[Myview alloc] initWithFrame:(0, 240, 320,240);
[self addSubview: view1];
[self addSibvoew: view2];
...
}
@interface MyView:UIView
...
@implement MyScrollView
...
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
//break points
//here comes event
}
Try this code.. 试试这个代码。
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(singleTapGestureCaptured:)];
[scroll addGestureRecognizer:singleTap];
- (void)singleTapGestureCaptured:(UITapGestureRecognizer *)touch{
CGPoint touchPoint=[gesture locationInView:scrollView];
touchPoint = [touch locationInView:self.view];
}
I suggest making ur two subview global and then in the superview touchesbegan method pass the touches and the event to the subviews for handling. 我建议将您的两个子视图设为全局,然后在超级视图中使用touchesbegan方法将触摸和事件传递给子视图进行处理。 So somethig like [view1 touchesBegan:touches event:event];
所以像[view1 touchesBegan:touches event:event]之类的东西; i have not tested it but that should be one way.
我没有测试过,但这应该是一种方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.