状态栏时钟在iPhoneX上已被截断 [英] Status Bar clock has been truncated on iPhoneX

查看:248
本文介绍了状态栏时钟在iPhoneX上已被截断的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在状态栏上添加渐变层并为不同的视图控制器使其变亮或变暗后,在导航中的某个随机点,缺口iPhone的状态栏中的时钟已被截断。像1 ...或...

After adding a gradient layer to the statusbar and make it light or dark for different view controllers, at some random point in navigation, my clock in the status bar of notch iPhones has become truncated. like 1... or ...

我已经尝试过这两种解决方案,以使statusbar内容变白;但这对随机时钟行为没有影响。

I have tried these two solutions for make statusbar content white; But this has no effect on this random clock behaviour.

this:

override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.navigationController?.navigationBar.barStyle = .blackOpaque
        self.setNeedsStatusBarAppearanceUpdate()
}

或以下方式:

override var preferredStatusBarStyle: UIStatusBarStyle {
        return .lightContent
}

这两个都更改了状态栏内容的颜色。关于造成这种行为的原因的任何想法?

Both of them changes my status bar color of content. Any idea about what is cause of this behavior???

这就是我制作状态栏渐变的方式:

and this is how I make the status bar gradient:

extension UIViewController {
    func makeStatusBarGradient(){
        let statusBarView = UIView(frame: UIApplication.shared.statusBarFrame)
        let gradientLayer1 = CAGradientLayer()
        gradientLayer1.frame = statusBarView.frame
        gradientLayer1.colors = [UIColor.APColors.redGradient.cgColor, UIColor.APColors.orangeGradient.cgColor]
        gradientLayer1.startPoint = CGPoint(x: 0.0, y: 0.5)
        gradientLayer1.endPoint = CGPoint(x: 1.0, y: 0.5)
        gradientLayer1.cornerRadius = 0
        gradientLayer1.zPosition = -10
        gradientLayer1.name = "gradient"
        //Change status bar color
        if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView{
            statusBar.layer.addSublayer(gradientLayer1)
        }
        setNeedsStatusBarAppearanceUpdate()
    }
    func clearStatusBarGradient(){
        if let statusBar = UIApplication.shared.value(forKey: "statusBar") as? UIView{
            if let layers = statusBar.layer.sublayers?.filter({$0.name == "gradient"}){
                if (layers.count > 0){
                    layers.first?.removeFromSuperlayer()
                }
            }
        }
        setNeedsStatusBarAppearanceUpdate()
    }
}

,并且APColor是:

and, the APColors are:

extension UIColor {
      struct APColors {
            static var redGradient : UIColor { return UIColor(red: 1.00, green: 0.42, blue: 0.24, alpha: 1) }
            static var orangeGradient : UIColor { return UIColor(red: 0.95, green: 0.19, blue: 0.42, alpha: 1)}

      }
}


推荐答案

您正在UILabel上使用扩展名,该扩展名覆盖了 intrinsicContentSize 。 (或者您可能正在使用此方法)所以状态栏时钟标签会触发它,并导致错误的internalContentSize。尝试使用此覆盖的方法修复textSize计算,或者尽可能避免覆盖它。

You are using extension on UILabel, which override it's intrinsicContentSize. (or maybe you swizzling this method) So status bar clock label trigger it and got wrong intrinsicContentSize. Try to fix textSize calculation in this overrided method, or avoid overriding it if possible.

我可以猜到您正在使用流行的SO答案中的UILabel + Padding,因此请检查您是否已经得到了:

I can guess you're using UILabel+Padding from popular SO answer, so check if you've got this:

if let insets = padding {
  insetsWidth += insets.left + insets.right
  insetsHeight += insets.top + insets.bottom
  textWidth -= insetsWidth
}

如果这样做,则只需对其进行更改:

if you do, then simply change it:

if let insets = padding {
  insetsWidth += insets.left + insets.right
  insetsHeight += insets.top + insets.bottom
  textWidth -= insetsWidth
} else {
  return contentSize
}

这篇关于状态栏时钟在iPhoneX上已被截断的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆