diff --git a/Tusker/Views/Status/BaseStatusTableViewCell.swift b/Tusker/Views/Status/BaseStatusTableViewCell.swift index bab4031c4..37f209744 100644 --- a/Tusker/Views/Status/BaseStatusTableViewCell.swift +++ b/Tusker/Views/Status/BaseStatusTableViewCell.swift @@ -361,23 +361,31 @@ class BaseStatusTableViewCell: UITableViewCell { let buttonImage = UIImage(systemName: collapsed ? "chevron.down" : "chevron.up")! - if animated, let buttonImageView = collapseButton.imageView { - // we need to use a keyframe animation for this, because we want to control the direction the chevron rotates - // when rotating ±π, UIKit will always rotate in the same direction - // using a keyframe to set an intermediate point in the animation allows us to force a specific direction - UIView.animateKeyframes(withDuration: 0.2, delay: 0, options: .calculationModeLinear, animations: { - UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) { - buttonImageView.transform = CGAffineTransform(rotationAngle: collapsed ? .pi / 2 : -.pi / 2) - } - UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) { - buttonImageView.transform = CGAffineTransform(rotationAngle: .pi) - } - }, completion: { (finished) in - buttonImageView.transform = .identity - self.collapseButton.setImage(buttonImage, for: .normal) - }) - } else { + if let buttonImageView = collapseButton.imageView { collapseButton.setImage(buttonImage, for: .normal) + + if animated { + buttonImageView.layer.opacity = 0 + + // this whole hack is necessary because when just rotating buttonImageView, it moves to the left of the button and then animates back to the center + let imageView = UIImageView(image: buttonImageView.image) + imageView.translatesAutoresizingMaskIntoConstraints = false + contentView.addSubview(imageView) + NSLayoutConstraint.activate([ + imageView.widthAnchor.constraint(equalTo: buttonImageView.widthAnchor), + imageView.heightAnchor.constraint(equalTo: buttonImageView.heightAnchor), + imageView.centerXAnchor.constraint(equalTo: collapseButton.centerXAnchor), + imageView.centerYAnchor.constraint(equalTo: collapseButton.centerYAnchor), + ]) + imageView.tintColor = .white + + UIView.animate(withDuration: 0.3, delay: 0) { + imageView.transform = CGAffineTransform(rotationAngle: .pi) + } completion: { _ in + imageView.removeFromSuperview() + buttonImageView.layer.opacity = 1 + } + } } if collapsed { diff --git a/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib b/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib index 5bcd4dae9..1437e6eb7 100644 --- a/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib +++ b/Tusker/Views/Status/ConversationMainStatusTableViewCell.xib @@ -81,10 +81,14 @@ - + + + + + diff --git a/Tusker/Views/Status/TimelineStatusTableViewCell.xib b/Tusker/Views/Status/TimelineStatusTableViewCell.xib index 000fe5341..3a19fff36 100644 --- a/Tusker/Views/Status/TimelineStatusTableViewCell.xib +++ b/Tusker/Views/Status/TimelineStatusTableViewCell.xib @@ -109,10 +109,16 @@ - + + + + + + +