how to get tap location from UIScrollview that covered by UITextview
HI all...
i have a textview as a subview of scrollview, the textview is cover all of scrollview area. i want to get location tap in scrollview, but the textview didn't passed it the case is, if i tap the textview, the tap is also detected in scrollview. can i do that?
this is my implementation :
-(void)viewWillAppear:(BOOL)animate开发者_如何学Cd{
UIGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
//tapScroll.numberOfTapsRequired = 2;
[self.scrollView addGestureRecognizer:tapScroll];
self.tapGesture = (UITapGestureRecognizer *)tapScroll;
tapScroll.delegate = self;
[tapScroll release];
}
-(void)handleTap:(UITapGestureRecognizer *)recognizer{
NSLog(@"handle tap");
location = [recognizer locationInView:self.scrollView];
[self.textView becomeFirstResponder];
NSLog(@"location tap x : %f, y : %f", location.x, location.y);
if (location.y < self.view.frame.size.height - keyBoardBounds.size.height) {
NSLog(@"HEIGHT : %f", self.view.frame.size.height - keyBoardBounds.size.height);
[self.scrollView setContentOffset:CGPointZero animated:YES];
}else {
[self.scrollView setContentOffset:CGPointMake(0, location.y/2) animated:YES];
}
}
i can't get the tap location, because the textview didn't passed it, can somebody help me, please??
Subclass the UITextView and override
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
Tutorial here
精彩评论