全部......
我有一个textview作为scrollview的子视图,textview覆盖了所有的scrollview区域。 我想在scrollview中获取位置,但textview没有通过它 情况是,如果我点击文本视图,也会在滚动视图中检测到点击。 我可以这样做吗?
这是我的实施:
-(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没有通过它,有人可以帮助我吗?
答案 0 :(得分:0)
对UITextView进行子类化并覆盖
- (BOOL)touchesShouldBegin:(NSSet *)touches withEvent:(UIEvent *)event inContentView:(UIView *)view
教程here