0

大家好...

我有一个文本视图作为滚动视图的子视图,文本视图覆盖了所有滚动视图区域。我想在滚动视图中获取位置点击,但文本视图没有通过它,如果我点击文本视图,则在滚动视图中也会检测到点击。我可以这样做吗?

这是我的实现:

-(void)viewWillAppear:(BOOL)animated{   
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];
}

}

我无法获得点击位置,因为 textview 没有通过它,有人可以帮助我吗?

4

1 回答 1

0

子类化 UITextView 并覆盖

- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view

教程在这里

于 2011-01-12T11:26:19.783 回答