iOS 11 inputAccessoryView broken

社会主义新天地 提交于 2019-12-02 22:03:27

问题


I have the following set up for my UIToolBar / Accessory View on a view controller

@IBOutlet var inputFieldView: UIToolbar!
override var canBecomeFirstResponder: Bool{
    return true
}

override var inputAccessoryView: UIView?{
    return self.inputFieldView
}

then inside my viewDidLoad I have:

    let seperator = UIView(frame: CGRect(x:0 , y: 0, width: ScreenSize.width(), height: 1))
    seperator.backgroundColor = UIColor.lightBackground
    self.inputFieldView.addSubview(seperator)
    self.inputFieldView.isTranslucent = false
    self.inputFieldView.setShadowImage(UIImage(), forToolbarPosition: .any)
    self.inputFieldView.setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)
    self.inputFieldView.removeFromSuperview()

This worked great for ios versions 10 and 9. It is a text view with a "Send" button. It sits at the bottom of the screen and when pressed, becomes first responder allowing the keyboard to come up and it positions itself correctly.

With ios 11 i cannot even click on it when it is at the bottom, so I cannot type at all.


回答1:


This is a known bug on iOS 11. UIToolbar subviews don't get the touch events because some internal views to the toolbar aren't properly setup.

The current workaround is to call toolBar.layoutIfNeeded() right before adding subviews.

In your case:

inputFieldView.layoutIfNeeded()

Hopefully this will get fixed on the next major version.




回答2:


Solved it. It looks like UIToolbar's just are not working correctly in iOS 11.

Changed it to an UIView and removed

self.inputFieldView.isTranslucent = false
self.inputFieldView.setShadowImage(UIImage(), forToolbarPosition: .any)
self.inputFieldView.setBackgroundImage(UIImage(), forToolbarPosition: .any, barMetrics: .default)

got it working (and changed it to a UIView from UIToolbar in the xib as well.)



来源:https://stackoverflow.com/questions/46371441/ios-11-inputaccessoryview-broken

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!