iOS中的暗模式问题

时间:2019-05-23 07:36:45

标签: ios swift view

我正在开发一个应用程序,其中我在设置中有一个开关按钮,当开关打开时,将整个应用程序视图更改为暗模式,当关闭时将其更改为原始视图。现在当我将应用程序更改为暗模式时变化完美,但是当我单击任何文本框并打开键盘时,会使我的整个视图变暗,看不到没有文本框或按钮,为什么会这样?我的使它们变暗和默认主题的代码是这样,

struct Theme {

static var backgroundColor:UIColor?
static var buttonTextColor:UIColor?
static var labelBackgroundColor:UIColor?
static var labelTextColor:UIColor?
static var buttonBackgroundColor:UIColor?
static var tableViewBackgroundColor:UIColor?
static var tableViewCellBackgroundColor:UIColor?
static var tabBarBackgroundColor:UIColor?
static var imageBackgroundColor:UIColor?


static public func defaultTheme() {
    self.backgroundColor = UIColor.white
    self.buttonTextColor = UIColor.black
    self.buttonBackgroundColor = UIColor.white
    self.labelBackgroundColor = UIColor.white
    self.labelTextColor = UIColor.black
    self.tableViewBackgroundColor = UIColor.white
    self.tableViewCellBackgroundColor = UIColor.white
    self.tabBarBackgroundColor = UIColor.white
    self.imageBackgroundColor = UIColor.clear
    updateDisplay()
}

static public func darkTheme() {
    self.backgroundColor = #colorLiteral(red: 0.2605174184, green: 0.2605243921, blue: 0.260520637, alpha: 1)
    self.buttonTextColor = UIColor.white
    self.buttonBackgroundColor = UIColor.clear
    self.labelBackgroundColor = UIColor.clear
    self.labelTextColor = UIColor.white
    self.tableViewBackgroundColor = UIColor.clear
    self.tableViewCellBackgroundColor = UIColor.white
    self.tabBarBackgroundColor = #colorLiteral(red: 0, green: 0.1673184633, blue: 0.3710786104, alpha: 1)
    self.imageBackgroundColor = UIColor.clear
    updateDisplay()
}

static public func updateDisplay() {
    let proxyButton = UIButton.appearance()
    proxyButton.setTitleColor(Theme.buttonTextColor, for: .normal)
    proxyButton.backgroundColor = Theme.buttonBackgroundColor

    let proxyView = UIView.appearance()
    proxyView.backgroundColor = backgroundColor

    let proxyLabel = UILabel.appearance()
    proxyLabel.backgroundColor = Theme.labelBackgroundColor
    proxyLabel.textColor = Theme.labelTextColor

    let proxyTableView = UITableView.appearance()
    proxyTableView.backgroundColor = Theme.tableViewBackgroundColor

    let proxyTableViewCell = UITableViewCell.appearance()
    proxyTableViewCell.backgroundColor = Theme.tableViewCellBackgroundColor

    let proxyTabBar = UITabBar.appearance()
    proxyTabBar.barTintColor = Theme.tabBarBackgroundColor

    let proxyImage = UIImageView.appearance()
    proxyImage.backgroundColor = Theme.imageBackgroundColor
}

} 现在我只是这样称呼它,当“切换”按钮为“打开”时,在应用程序委托中Theme.darkTheme()。启用暗模式时,我单击文本字段并打开键盘,它会隐藏这样的视图,

enter image description here

我该如何解决?

0 个答案:

没有答案