search

Home  >  Q&A  >  body text

swift - IOS inputAccessoryView和canBecomeFirstResponder

第一个问题:inputAccessoryView通过计算属性改变了toolBar的位置,为什么直接把toolBar变成了inputAccessoryView的子视图,而不是self.view的子视图呢
第二个问题:canBecomeFirstResponder一旦变成true为啥inputAccessoryView就会默认出现呢,为啥不用写inputAccessoryView.becomeFirstResponder
第三个问题:toolBar和textView同样背景色都是黑色,为什么toolBar展现出来就变成灰色了,怎么让它变成黑色
附加问题:如果textView自适应行数后变大,如何让toolBar和inputAccessoryView都自适应变大呢,类似于QQ的聊天输入框,请给个思路,当然有代码更好啦 ^_^
小弟初学,请大神们不吝赐教

大家讲道理大家讲道理2773 days ago731

reply all(1)I'll reply

  • 黄舟

    黄舟2017-04-17 17:35:30

    1. Return toolbar when getting. When the system retrieves inputAccessoryView, the value is toolBar. I personally don’t understand the first question of the questioner. I suggest you try using didSet?
    2. InputAccessoryView does not appear automatically when it is nil. In other cases, It will appear automatically with the keyboard
    3. You can use Xcode's Debug → View Debugging → Capture View Hierarchy to observe the view at runtime
    4. textView adaptive

    private func heightForString(textView: UITextView, width: CGFloat) -> CGFloat {
            let sizeToFit = textView.sizeThatFits(CGSize(width: width, height: CGFloat(MAXFLOAT)))
            return sizeToFit.height
    }

    reply
    0
  • Cancelreply