gpt4 book ai didi

ios - 单击时折叠和展开 UI

转载 作者:行者123 更新时间:2023-11-29 05:32:41 39 4
gpt4 key购买 nike

我希望我的 commentTable 在点击时展开,然后在第二次点击时折叠。

  var commentsInt = -1
@IBOutlet weak var commentsTop: NSLayoutConstraint!
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if commentsInt == -1
{
commentsInt = 1
}
if commentsInt == 0{

commentsTop.constant = 8
commentsInt = 1
}

if commentsInt == 1 {
commentsTop.constant = -220
commentsInt = 0

}

}

这个函数可以扩展表格(虽然没有动画看起来有点笨拙),但我无法在第二次单击时收缩表格。

同样,我想在滚动时展开一个textView(您不能编辑这个名为mainText的textView)。所以我尝试了

var mainInt = -1
@IBOutlet weak var mainHeight: NSLayoutConstraint!
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if mainInt == -1
{
mainInt = 1
}
if mainInt == 0{

mainHeight.constant = 440
mainInt = 1
}

if mainInt == 1 {
mainHeight.constant = 120
mainInt = 0

}
}

但是当我滚动时 mainText 根本不展开。我该如何解决这些问题?

最佳答案

认为您每次点击都会将高度设置两次。试试这个:

var commentsInt = -1
@IBOutlet weak var commentsTop: NSLayoutConstraint!

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if commentsInt == -1
{
commentsInt = 1
}
if commentsInt == 0{

commentsTop.constant = 8
commentsInt = 1
} else if commentsInt == 1 {
commentsTop.constant = -220
commentsInt = 0

}

}

关于ios - 单击时折叠和展开 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57384126/

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