如何从 UIScrollview 获取 UITextview 覆盖的点击位置

发布于 2024-10-11 07:21:04 字数 1164 浏览 3 评论 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];
}

}

我无法获取点击位置,因为文本视图没有通过它,有人可以帮助我吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

捶死心动 2024-10-18 07:21:04

将 UITextView 子类化并

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

此处重写教程

Subclass the UITextView and override

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

Tutorial here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文