如何从 UIScrollview 获取 UITextview 覆盖的点击位置
大家好...
我有一个文本视图作为滚动视图的子视图,文本视图覆盖了所有滚动视图区域。 我想在滚动视图中获取位置点击,但文本视图没有通过它 情况是,如果我点击文本视图,滚动视图中也会检测到点击。 我可以这样做吗?
这是我的实现:
-(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];
}
}
我无法获取点击位置,因为文本视图没有通过它,有人可以帮助我吗?
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)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];
}
}
i can't get the tap location, because the textview didn't passed it, can somebody help me, please??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将 UITextView 子类化并
在此处重写教程
Subclass the UITextView and override
Tutorial here