- (void)touchesBegan:(NSSet *)触及withEvent:(UIEvent *)event {}不起作用

时间:2013-08-07 09:45:49

标签: iphone ios uiview uiscrollview

我打电话给方法,

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

      }

为了辞职第一个responder.it工作正常而不使用scrollview.but如果我使用scrollview我不能使用此方法。为什么?

1 个答案:

答案 0 :(得分: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 prevents touchesBegan, touchesMoved, touchesEnded on view controllerUIScrollView touchesBegan