0

因此,我制作了一个带有自定义操作菜单的 UItableViewCells,通过点击单元格从右侧滑动打开,并在任何地方使用约束对其进行布局。如果我在显示按钮时尝试更改标签,则单元格本身会奇怪地跳转到开始位置。

这是一些图片:

打开操作后的图像。

然后点击绿色按钮必须改变颜色和文本,但单元格突然跳跃,看起来像这样

单元格滑动的代码是:

 UIView.animateWithDuration(0.5, animations: {
        if !self.state {
            self.contentView.layer.position.x -= self.actionViewWidth                       // contentView
            self.viewWithTag(5)?.layer.position.x -= self.actionViewWidth                   // actionView
            self.logoImageView.layer.position.x += self.actionViewWidth - self.padding * 2  // imageView
            self.nameLabel.alpha = self.hide                                                // nameLabel
            self.cellarLabel.alpha = self.show                                              // cellarLabel
            self.state = true

        } else {
            self.contentView.layer.position.x += self.actionViewWidth                       // contentView
            self.viewWithTag(5)?.layer.position.x += self.actionViewWidth                   // actionView
            self.logoImageView.layer.position.x -= self.actionViewWidth - self.padding * 2  // imageView
            self.nameLabel.alpha = self.show                                                // nameLabel
            self.cellarLabel.alpha = self.hide                                              // cellarLabel

            self.state = false
        }
        }

这是必须更改文本的动画:

 UIView.animateWithDuration(0.15, animations: {
        self.imageView.alpha = 0
        self.subLabel.alpha = 0
        self.backgroundColor = UIColor(red:0.97, green:0.91, blue:0.11, alpha:1.0)
        self.layoutIfNeeded()
        }, completion: { (_) -> Void in
            self.subAttributes[NSForegroundColorAttributeName] = UIColor(red:0.61, green:0.61, blue:0.61, alpha:1.0)
            self.subAttributes[NSUnderlineStyleAttributeName] = NSUnderlineStyle.StyleNone.rawValue
            self.subLabel.attributedText = NSAttributedString(string: "Waiting", attributes: self.subAttributes) // this line crashes the contsraints
            UIView.animateWithDuration(0.15) {
                self.subLabel.alpha = 1
                self.label.alpha = 1
                self.layoutIfNeeded()
            }
            self.layoutIfNeeded()
        })
4

0 回答 0