当前位置:  开发笔记 > 编程语言 > 正文

在iOS中旋转时,inputAccessoryView的UIToolbar变黑

如何解决《在iOS中旋转时,inputAccessoryView的UIToolbar变黑》经验,为你挑选了1个好方法。

这是我的代码:

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
}

当我转动设备时,UIToolBar变黑了(点击再次查看此GIF)

黑色

那么无论如何要修复它?谢谢!

顺便说一句:在模拟器中,我看不到UIToolBar变黑了.



1> He Yifei 何一非..:

通过添加修复:(仍然不清楚导致它的原因)

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)是这里 UIToolBar的默认背景颜色)

推荐阅读
吻过彩虹的脸_378
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有