在iOS中旋转时,inputAccessoryView的UIToolbar变黑 [英] inputAccessoryView's UIToolbar turns black when rotating in iOS
本文介绍了在iOS中旋转时,inputAccessoryView的UIToolbar变黑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
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)
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:在模拟器中,我看不到UIToolBar变黑。
BTW: In Simulator I cannot see UIToolBar turning black.
推荐答案
通过添加修复:(仍然不清楚导致它的原因)
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),绿色:(247/255),蓝色:(247/255),alpha:1)
是来自此处的UIToolBar的默认背景颜色。
(UIColor(colorLiteralRed: (247/255), green: (247/255), blue: (247/255), alpha: 1)
is the default background color of the UIToolBar from here)
这篇关于在iOS中旋转时,inputAccessoryView的UIToolbar变黑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文