gpt4 book ai didi

ios - 使用交换(_ :_:) with two different types

转载 作者:行者123 更新时间:2023-11-28 06:12:55 25 4
gpt4 key购买 nike

我目前有我的主视图设置,当我点击一个 UILabel 时,它会将其“不透明度”更改为 0,并且会出现一个文本字段,该文本字段最初是隐藏的并且其“不透明度设置为 0”上述值反转 (hidden = false, opacity = 1)。

我打算经常交换这两个 View 之间的值,所以我认为使用 swap(_:_:) 函数是理想的选择。不幸的是,我收到此错误,因为 UILabelUITextField 不是同一类型:

无法转换“UITextField!”类型的值到预期的参数类型“UILabel”

有什么办法可以解决这个问题,还是我会被困在创建自己的函数中?

@IBAction func onTapToEnterBillAmount(_ sender: UITapGestureRecognizer) {
UIView.animate(withDuration: 0.2, animations: {
swap(&self.tapToEnterBillAmountLabel, &self.billAmountTextField)
})
}

最佳答案

由于 swap(_:_:) 要求两个参数的类型相同,请尝试交换 UIButton/UILabel< 的实际匹配属性:

@IBAction func onTapToEnterBillAmount(_ sender: UITapGestureRecognizer) {
UIView.animate(withDuration: 0.2, animations: {
swap(&self.tapToEnterBillAmountLabel.alpha, &self.billAmountTextField.alpha)
}, completion: { _ in
swap(&self.tapToEnterBillAmountLabel.isHidden, &self.billAmountTextField.isHidden)
})
}

关于ios - 使用交换(_ :_:) with two different types,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45985292/

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