Ios 工具栏上的“完成”按钮有时消失,有时变为白色
我在iOS swift项目的键盘上方有一个工具栏。当我点击我的应用程序并进入某些页面,然后再进入带有工具栏的页面时,“完成”按钮不见了。如果您单击页面上的另一个文本字段,它会返回,直到您返回到应用程序的页面将其搞乱为止。如果我移除灵活的空格键,它永远不会消失。我已经检查了工具栏的框架大小,它似乎从未改变。按钮有时也会变成白色。如果有人有任何想法,我不知道这是怎么发生的?此congifureToolbar()在viewdidload中调用。我还尝试在viewdidappear中调用它,并尝试调用LayoutSubView。inputToolbar只是一个UIToolbar()。我试过使用自定义xib工具栏、自定义xib视图、第三方库工具栏,但从来没有什么不同Ios 工具栏上的“完成”按钮有时消失,有时变为白色,ios,swift,uibarbuttonitem,uitoolbar,Ios,Swift,Uibarbuttonitem,Uitoolbar,我在iOS swift项目的键盘上方有一个工具栏。当我点击我的应用程序并进入某些页面,然后再进入带有工具栏的页面时,“完成”按钮不见了。如果您单击页面上的另一个文本字段,它会返回,直到您返回到应用程序的页面将其搞乱为止。如果我移除灵活的空格键,它永远不会消失。我已经检查了工具栏的框架大小,它似乎从未改变。按钮有时也会变成白色。如果有人有任何想法,我不知道这是怎么发生的?此congifureToolbar()在viewdidload中调用。我还尝试在viewdidappear中调用它,并尝试调用L
func configureToolBar() {
inputToolbar.barTintColor = UIColor.groupTableViewBackground
inputToolbar.barStyle = .default
inputToolbar.isTranslucent = false
inputToolbar.sizeToFit()
inputToolbar.tintColor = UIColor(red: 0/255, green: 102/255, blue: 252/255, alpha: 1.0)
inputToolbar.setShadowImage(AppColors.shared.tableViewSeparatorColor.as1ptImage(), forToolbarPosition: .any)
let doneButton = UIBarButtonItem(title: "Done", style: .done, target: self, action: #selector(dismissKeyboard))
let flexibleSpaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
let fixedSpaceButton = UIBarButtonItem(barButtonSystemItem: .fixedSpace, target: nil, action: nil)
doneButton.tintColor = UIColor(red: 0/255, green: 102/255, blue: 252/255, alpha: 1.0)
doneButton.setTitleTextAttributes([NSAttributedStringKey.foregroundColor : UIColor(red: 0/255, green: 102/255, blue: 252/255, alpha: 1.0)], for: .normal)
let nextButton = UIBarButtonItem(image: imageLiteral(resourceName: "toolbar-down"), style: .plain, target: self, action: #selector(moveToNextInput))
nextButton.tintColor = AppColors.shared.blackColor
nextButton.width = 50.0
let previousButton = UIBarButtonItem(image: imageLiteral(resourceName: "toolbar-up"), style: .plain, target: self, action: #selector(moveToPreviousInput))
previousButton.tintColor = AppColors.shared.blackColor
inputToolbar.setItems([fixedSpaceButton, previousButton, fixedSpaceButton, nextButton, fixedSpaceButton, doneButton], animated: false)
inputToolbar.isUserInteractionEnabled = true
}
如果我没有使用灵活的空格按钮,而是使用固定空格按钮,我可以看到“完成”按钮被推离屏幕,因为我可以将其部分切断。听起来问题不在于您显示的代码,而在于工具栏本身进入界面的方式。对于项目消失问题,使用xcode调试工具查看它与以下内容一起放入的视图层次结构将非常有用:textField.inputAccessoryView=inputToolbar,如果这是您所要求的?好的,我将检查调试工具