I have a segmentedControl
and I set it up like this:
func setUpSegmentedControl() {
customSC.setTitle("??", forSegmentAt: 0)
customSC.setTitle("??", forSegmentAt: 1)
customSC.selectedSegmentIndex = 0
customSC.translatesAutoresizingMaskIntoConstraints = false
customSC.subviews.flatMap{$0.subviews}.forEach { subview in
if let imageView = subview as? UIImageView, let image = imageView.image, image.size.width > 5 {
// The imageView which isn't separator
imageView.contentMode = .scaleAspectFit
}
}
// Add target action method
customSC.addTarget(self, action: #selector(segControlAction(sender:)), for: .valueChanged)
}
Now as you can see there are two segments. What I am trying to achieve is that after some action the title
at segment 0
should be animated like this:
UIView.animate(withDuration: 0.1, animations: {
let scale = 1.3
self.friendButton.transform = self.friendButton.transform.scaledBy(x: scale, y: scale)
}, completion: { _ in
UIView.animate(withDuration: 0.1, animations: {
self.friendButton.transform = CGAffineTransform.identity
})
})
question from:
https://stackoverflow.com/questions/65945410/swift-animate-image-inside-segmented-control 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…