UITextField显示异常

时间:2016-11-29 07:16:54

标签: objective-c swift autolayout uitextfield uikeyboard

我的viewController中有一个带有textField和两个btns的inputBar,它的布局如下:

enter image description here

橙色部分视图是textField,而我还没有将它们设置为backgroundColor。

当我在内容已经超出显示的textField范围时尝试连续输入一些单词时,左侧开关btn放置的位置会闪烁一部分被遮挡的textField内容。

这种情况只会出现在输入中文字符

视图有我的布局代码:

    self.backgroundColor = .lightGray
    self.addSubview(switchBtn)
    switchBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
    switchBtn.setTitle("switch", for: .normal)
    switchBtn.setTitleColor(.white, for: .normal)
    switchBtn.snp.makeConstraints { (make) in
        make.leading.equalToSuperview()
        make.width.equalToSuperview().multipliedBy(1/8.0)
        make.top.bottom.equalToSuperview()
    }

    self.addSubview(sendBtn)
    sendBtn.titleLabel?.font = UIFont.systemFont(ofSize: 16)
    sendBtn.setTitle("send", for: .normal)
    sendBtn.setTitleColor(.white, for: .normal)
    sendBtn.snp.makeConstraints { (make) in
        make.width.equalTo(switchBtn)
        make.top.bottom.trailing.equalToSuperview()
    }
    self.insertSubview(inputBar, at: 0)
    inputBar.backgroundColor = .orange
    inputBar.snp.makeConstraints { (make) in
        make.leading.equalTo(switchBtn.snp.trailing)
        make.top.equalToSuperview().offset(4)
        make.bottom.equalToSuperview().offset(-4)
        make.trailing.equalTo(sendBtn.snp.leading)
    }

我已经编写了相同的功能代码使用Objective-C,它出现了同样的问题,你能告诉我我的问题在哪里吗?

1 个答案:

答案 0 :(得分:0)

我没有剩下的代码,所以很难肯定,但文本字段是为了滚动而设计的。当剪辑子视图关闭时,在文本字段外滚动的内容仍然可见。