對不起,但一個非常基本的初學者的問題:想象一下有一個UITextField和一個UITextView。然後,想象一下放置在這些TextField/View上方的透明UIView,如果您觸摸它們,它們將不會響應。如果你觸摸(而不是刷卡或捏等)UIView,我希望無論用戶觸摸(即TextField或視圖)成爲第一響應者。有沒有類似的命令:cocoa-touch:如何找出哪個對象被觸摸
[objectThatWasTouched becomeFirstResponder];
?
我需要這個在下面的方法。現在,它被設置成UITextView的成爲第一個響應者,但我想任何觸摸對象,成爲第一個響應者:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
[super touchesMoved:touches withEvent:event];
UITouch *touch = [touches anyObject];
CGPoint currentPosition = [touch locationInView:self.view];
CGFloat deltaX = fabsf(gestureStartPoint.x - currentPosition.x); // will always be positive
CGFloat deltaY = fabsf(gestureStartPoint.y - currentPosition.y); // will always be positive
if (deltaY == 0 && deltaX == 0) {
[self.view bringSubviewToFront:aSwipeTextView];
[self.view bringSubviewToFront:noteTitle];
[self.view bringSubviewToFront:doneEdit];
[aSwipeTextView becomeFirstResponder];
}
}
最後,我需要某種方法來擺脫第一響應者,即取決於任何第一響應者。這將只得到擺脫firstresponder的,當UITextView的已經感動:
- (IBAction)hideKeyboard
{
[aSwipeTextView resignFirstResponder];
[self.view bringSubviewToFront:canTouchMe];
}
感謝您的想法。我其實只是發佈了一個相關的問題:http://stackoverflow.com/questions/7597909/defining-maximum-variance-of-an-uitextview – 2011-10-01 13:18:55