0

私のプログラムには 2 つのビュー (scrollView-super、view-sub*2) があります。

私の場合、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
}
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

2 つのサブビューをグローバルにしてから、スーパービューの touchesbegan メソッドでタッチとイベントをサブビューに渡して処理することをお勧めします。[view1 touchesBegan:touches event:event]; のようなものです。私はそれをテストしていませんが、それは一つの方法であるべきです.

于 2011-09-26T03:17:40.230 に答える