Paul Taylor
Paul Taylor

Reputation: 53

Transition Animations on Images

Good morning. The segmented control works fine in the static state for the images. However, I am trying to add a transition (curl down) to the images under segment control, but am not understanding how best to implement the code. Appreciate any help on this.

class images: UIViewController {

@IBOutlet var segmentCtrl1: UISegmentedControl!

@IBOutlet var imageView: UIImageView!

override func viewDidLoad() { super.viewDidLoad()

}

@IBAction func segmentCtrlChange(_ sender: UISegmentedControl) {
    UIView.transition(with: imageView, duration: 0.3, options: [.transitionCurlDown], animations: { self.imageView.image = image
    })
    
    switch sender.selectedSegmentIndex {
    
    case 0:
        imageView.image = UIImage(named: "footsteps.jpg")!
    case 1:
        imageView.image = UIImage(named: "birds.jpg")!
    case 2:
        imageView.image = UIImage(named: "apples.jpg")!
    default:
        imageView.image = UIImage(named: "space.jpg")!
    }
}

}

Upvotes: 1

Views: 229

Answers (1)

Paul Taylor
Paul Taylor

Reputation: 53

Your suggestion put me on the right road... I played around with the self and got the code to work.

@IBAction func segmentCtrlChange(_ sender: UISegmentedControl) {
    UIView.transition(with: imageView, duration: 0.3, options: [.transitionCurlDown], animations: {
        switch sender.selectedSegmentIndex {
        case 0:
            self.imageView.image = UIImage(named: "footsteps.jpg")!
        case 1:
            self.imageView.image = UIImage(named: "birds.jpg")!
        case 2:
            self.imageView.image = UIImage(named: "apples.jpg")!
        default:
            self.imageView.image = UIImage(named: "space.jpg")!
        }
    })
}

Upvotes: 2

Related Questions