在我的程序中有两个视图(scrollView-super,view-sub * 2)。
在我的例子中,两个子视图在scrollView中进行了子视图。在子视图中调用touchesBegan事件。
如何在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
}
答案 0 :(得分:1)
试试这段代码..
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];
}
答案 1 :(得分:0)
我建议将你的两个子视图设为全局,然后在superview中使用touchesbegan方法将触摸和事件传递给子视图进行处理。有些像[view1 touchesBegan:touches event:event]; 我没有测试过,但这应该是一种方式。