0

在我的程序中有两个视图(scrollView-super、view-sub*2)。

在我的情况下,两个子视图在滚动视图中被子视图。在子视图中调用的 touchesBegan 事件。

如何在滚动视图中获取事件???

@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
}
4

2 回答 2

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];  
}
于 2011-09-26T05:51:28.050 回答
0

我建议让你的两个子视图全局化,然后在 superview touchesbegan 方法中将触摸和事件传递给子视图进行处理。所以像 [view1 touchesBegan:touches event:event]; 我没有测试过,但这应该是一种方法。

于 2011-09-26T03:17:40.230 回答