滚动视图中嵌入的较低文本字段未接收到触摸

时间:2018-03-21 22:00:35

标签: ios objective-c autolayout textfield

我有很多文本字段垂直排列在滚动视图中,最下面是一个textview。所有都在故事板中连接到.h文件中的出口,也连接到触发方法以启用保存按钮的操作方法。所有人都在viewdid加载中设置了他们的代理。但是,底部文本字段 - 屏幕底部显示在屏幕上的那些文本字段不响应触摸。

打开屏幕时可见的文本字段响应触摸。下面的字段没有。这令人费解。我正在使用autolayout但是已经尝试了各种各样的视图,contentview和scrollview大小的设置而没有成功。现在我把它们都放在相同的尺寸(667高度)。

使用可视化调试器我没有看到阻止文本字段的任何视图。我确实看到了滚动视图。由于scrollview有一个手势识别器,我已经放入了代码来屏蔽文本字段的触摸而没有运气。

任何人都可以建议可能出错的地方吗?

Here is some code that might be relevant:
//in view will appear
//for dismissing keynoard from scroll
    UITapGestureRecognizer *tapScroll = [[UITapGestureRecognizer alloc]initWithTarget:self     action:@selector(tapped)];
    tapScroll.cancelsTouchesInView = TRUE;//was no
    [self.scrollView addGestureRecognizer:tapScroll];

- (void) tapped
{
    NSLog(@"tapped fired");
    [self.view endEditing:YES];
}
//setting delegates
self.titleField.delegate=self;
    self.firstField.delegate=self;
    self.lastField.delegate = self;
    self.emailField.delegate=self;
    self.email2Field.delegate=self;
    self.telField.delegate=self;
    self.mobField.delegate=self;
    self.telmainField.delegate=self;
    self.teltollField.delegate=self;
    self.telhField.delegate=self;
    self.telfaxField.delegate=self;
    self.jobtitleField.delegate = self;
    self.coField.delegate = self;
    self.addr1Field.delegate = self;

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
    NSLog(@"gesture recognizer should receive touch");

    // Disallow recognition of tap gestures in the segmented control.
    if ((touch.view == _titleField)||(touch.view == _firstField)||(touch.view == _lastField)||(touch.view == _emailField)||(touch.view == _email2Field)
        ||(touch.view == _telField)||(touch.view == _mobField)||(touch.view == _telmainField)||(touch.view == _teltollField)||(touch.view == _telhField)||(touch.view == _telfaxField)||(touch.view == _jobtitleField)||(touch.view == _coField)||(touch.view == _addr1Field)) {//change it to your condition
        return NO;
    }
    else {
        return YES;
    }
}

- (void)viewDidLayoutSubviews {
    self.scrollView.contentSize = CGSizeMake(320, 1200);
}

0 个答案:

没有答案