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];
}

}

テキストビューが通過しなかったため、タップ位置を取得できません。誰か助けてください??

4

1 に答える 1

0

UITextView をサブクラス化し、オーバーライドする

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

チュートリアルはこちら

于 2011-01-12T11:26:19.783 に答える