inputAccessoryView's UIToolbar turns black when rotating in iOS

混江龙づ霸主 提交于 2019-12-07 03:07:44

问题


Here is my code:

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

    let keyBoardToolBar = UIToolbar(frame: CGRectMake(0, 0, self.view.frame.size.width, 44))
    keyBoardToolBar.barStyle = .Default

    let flexSpaceKeyboardBarButtonItem = UIBarButtonItem(barButtonSystemItem: .FlexibleSpace, target: nil, action: nil)

    let doneKeyboardBarButtonItem = UIBarButtonItem(title: "Done", style: .Done, target: self, action: nil)

    let wordKeyboardBarButtonItem = UIBarButtonItem(title: "Button 1", style: .Plain, target: self, action: nil)

    var barItems: [UIBarButtonItem] = []
    barItems.append(wordKeyboardBarButtonItem)
    barItems.append(flexSpaceKeyboardBarButtonItem)
    barItems.append(doneKeyboardBarButtonItem)

    keyBoardToolBar.setItems(barItems, animated: true)

    self.myTV.inputAccessoryView = keyBoardToolBar
}

And when I am turning the device, the UIToolBar become black: (click to see this GIF again)

So is there anyway to fix it? Thanks!

BTW: In Simulator I cannot see UIToolBar turning black.


回答1:


Fixed by adding: (still unclear about the reason causing it though)

keyBoardToolBar.isTranslucent = false
keyBoardToolBar.barTintColor = UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1)

(UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1) is the default background color of the UIToolBar from here)



来源:https://stackoverflow.com/questions/34289951/inputaccessoryviews-uitoolbar-turns-black-when-rotating-in-ios

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