简体   繁体   中英

How can I get touchesBegan event on SuperView

In my program there is two views(scrollView-super, view-sub*2).

In my case two subviews are subviewed in scrollView. touchesBegan event called in subviews.

How Can I get event in 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. So somethig like [view1 touchesBegan:touches event:event]; i have not tested it but that should be one way.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM