【问题标题】:how to get tap location from UIScrollview that covered by UITextview如何从 UITextview 覆盖的 UIScrollview 获取点击位置
【发布时间】:2011-01-12 11:02:18
【问题描述】:

大家好...

我有一个文本视图作为滚动视图的子视图,文本视图覆盖了所有滚动视图区域。 我想在滚动视图中获取位置点击,但文本视图没有通过它 情况是,如果我点击 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 没有通过它,请有人帮助我吗??

【问题讨论】:

    标签: iphone uiscrollview location uitextview tap


    【解决方案1】:

    继承 UITextView 并覆盖

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

    教程here

    【讨论】:

    • 我已经这样做了,但是textview仍然没有通过手势,你能告诉我怎么做吗?
    猜你喜欢
    • 1970-01-01
    • 2014-10-08
    • 1970-01-01
    • 2012-05-20
    • 1970-01-01
    • 2019-01-14
    • 1970-01-01
    • 1970-01-01
    • 2021-06-27
    相关资源
    最近更新 更多