2021年5月26日 星期三

swift 5: iPadOS textField 進入輸入模式(出現 keyboard) 畫面, 就會出現一堆錯誤訊息

 

類似下面這些一長串錯誤訊息

(
  "<NSAutoresizingMaskLayoutConstraint:0x281fe1b30 h=--& v=--& _UIButtonBarButton:0x1290c0cd0.height == 0  (active)>",
  "<NSLayoutConstraint:0x281ffa440 V:|-(6)-[_UIUCBKBSelectionBackground:0x1290c14c0]  (active, names: '|':_UIButtonBarButton:0x1290c0cd0 )>",
  "<NSLayoutConstraint:0x281ffa3a0 _UIUCBKBSelectionBackground:0x1290c14c0.bottom == _UIButtonBarButton:0x1290c0cd0.bottom - 6  (active)>"
)

解決來源:

Strange UIButtonBarButton layout errors on all textView, fields and searchbars on iPad only

解決方法:

// Workaround to remove autolayout errors when keyboard shows on iPad.
// <NSAutoresizingMaskLayoutConstraint:0x28376afd0 h=--& v=--& _UIButtonBarButton:0x107f0ce30.height == 0   (active)>
// Introduced approx iOS 14.2 according to https://developer.apple.com/forums/thread/667441
// Side effect: Removes the redo/undo and paste buttons from the keyboard
let item = textField.inputAssistantItem
item.leadingBarButtonGroups = []
item.trailingBarButtonGroups = []

沒有留言:

張貼留言