gpt4 book ai didi

ios - iPhone 上的状态栏时钟已被截断

转载 作者:搜寻专家 更新时间:2023-11-01 06:26:21 25 4
gpt4 key购买 nike

在向状态栏添加渐变层并针对不同的 View Controller 使其变亮或变暗后,在导航中的某个随机点,我在缺口 iPhone 的状态栏中的时钟已被截断。像 1... 或 ...

我已经尝试了这两种将状态栏内容变白的解决方案;但这对这种随机时钟行为没有影响。

这个:

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

或者这个:

override var preferredStatusBarStyle: UIStatusBarStyle {
return .lightContent
}

它们都改变了我状态栏内容的颜色。知道这种行为的原因是什么吗???

clock problem

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

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()
}
}

并且,APColors 是:

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。 (或者也许你调配了这个方法)所以状态栏时钟标签触发它并且得到了错误的 intrinsicContentSize。尝试修复此覆盖方法中的 textSize 计算,或尽可能避免覆盖它。

我猜你正在使用流行的 SO 答案中的 UILabel+Padding,所以检查你是否有这个:

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

如果你这样做,那么简单地改变它:

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

关于ios - iPhone 上的状态栏时钟已被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54003135/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com