-2

我调用了这个方法,

     - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [super touchesBegan:touches withEvent:event];
    [self.name resignFirstResponder];
    [self.userName resignFirstResponder];
    [self.mailId resignFirstResponder];
    [self.password resignFirstResponder];
    [self.reTypePassword resignFirstResponder];

      }

出于辞职第一响应者的目的。它可以在不使用滚动视图的情况下正常工作。但是如果我使用滚动视图,我将无法使用此方法。为什么?

4

1 回答 1

3

如果需要使用滚动视图,可以添加手势识别器。尝试这个:

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(resignFirstResponder:)];
 gestureRecognizer.delegate = self;
 [scrollView addGestureRecognizer:gestureRecognizer];


-(void) resignFirstResponder:(UITapGestureRecognizer *) gesture
 {
    [self.name resignFirstResponder];
    [self.userName resignFirstResponder];
    [self.mailId resignFirstResponder];
    [self.password resignFirstResponder];
    [self.reTypePassword resignFirstResponder];

 }

还有更多的选择:参见 UIScrollView 防止 touchesBegan、touchesMoved、touchesEnded on view controllerUIScrollView touchesBegan

于 2013-08-07T09:58:48.380 回答