Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
276 views
in Technique[技术] by (71.8m points)

ios - Swift Animate Image inside Segmented Control

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...