gpt4 book ai didi

ios - 表达式过于复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式

转载 作者:行者123 更新时间:2023-11-28 13:06:40 24 4
gpt4 key购买 nike

当我编译以下代码时:

  override func layoutSubviews() {
super.layoutSubviews()

let selectedBackgroundWidth = bounds.width / 2.0 - selectedBackgroundInset * 2.0
selectedBackgroundView.frame = CGRect(x: selectedBackgroundInset + CGFloat(selectedIndex) * (selectedBackgroundWidth + selectedBackgroundInset * 2.0), y: selectedBackgroundInset, width: selectedBackgroundWidth, height: bounds.height - selectedBackgroundInset * 2.0)

(titleLabelsContentView.frame, selectedTitleLabelsContentView.frame) = (bounds, bounds)

let titleLabelMaxWidth = bounds.width / 2.0 - selectedBackgroundInset * 2.0
let titleLabelMaxHeight = bounds.height - selectedBackgroundInset * 2.0

let leftTitleLabelSize = leftTitleLabel.sizeThatFits(CGSize(width: titleLabelMaxWidth, height: titleLabelMaxHeight))
let leftTitleLabelOrigin = CGPoint(x: floor((bounds.width / 2.0 - leftTitleLabelSize.width) / 2.0), y: floor((bounds.height - leftTitleLabelSize.height) / 2.0))
let leftTitleLabelFrame = CGRect(origin: leftTitleLabelOrigin, size: leftTitleLabelSize)
(leftTitleLabel.frame, selectedLeftTitleLabel.frame) = (leftTitleLabelFrame, leftTitleLabelFrame)

let rightTitleLabelSize = rightTitleLabel.sizeThatFits(CGSize(width: titleLabelMaxWidth, height: titleLabelMaxHeight))
let rightTitleLabelOrigin = CGPoint(x: floor(bounds.size.width / 2.0 + (bounds.width / 2.0 - rightTitleLabelSize.width) / 2.0), y: floor((bounds.height - rightTitleLabelSize.height) / 2.0))
let rightTitleLabelFrame = CGRect(origin: rightTitleLabelOrigin, size: rightTitleLabelSize)
(rightTitleLabel.frame, selectedRightTitleLabel.frame) = (rightTitleLabelFrame, rightTitleLabelFrame)
}

我收到以下错误:

Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

我在另一个项目中尝试了代码,它编译没有问题。

我该如何解决这个问题?

enter image description here

最佳答案

尝试像这样分开你的计算:

let rightTitleLabelSize = rightTitleLabel.sizeThatFits(CGSize(width: titleLabelMaxWidth, height: titleLabelMaxHeight))
let x = floor(bounds.size.width / 2.0 + (bounds.width / 2.0 - rightTitleLabelSize.width) / 2.0)
let y = floor((bounds.height - rightTitleLabelSize.height) / 2.0)
let rightTitleLabelOrigin = CGPoint(x: x, y: y)
let rightTitleLabelFrame = CGRect(origin: rightTitleLabelOrigin, size: rightTitleLabelSize)
(rightTitleLabel.frame, selectedRightTitleLabel.frame) = (rightTitleLabelFrame, rightTitleLabelFrame)

关于ios - 表达式过于复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32543434/

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