Create animation of a UIImageView between two contentMode ( UIViewContentModeScaleAspectFill / UIViewContentModeScaleAspectFit )
My WebSite - My TwitterCompatible Swift 3.0
To see a demo video, click here
![ScreenShot Demo Video](https://github.com/VivienCormier/UIImageViewModeScaleAspect/raw/master/Example/UIImageViewModeScaleAspect/UIImageViewModeScaleAspect/example_1.png?raw=true&raw=true)
![ScreenShot Demo Video](https://github.com/VivienCormier/UIImageViewModeScaleAspect/raw/master/Example/UIImageViewModeScaleAspect/UIImageViewModeScaleAspect/example_2.png?raw=true&raw=true)
Use Pod (or download and add "UIImageViewModeScaleAspect.swift" in your xcodeprojet.) :
pod 'UIImageViewModeScaleAspect'
Init the UIImageViewModeScaleAspect. Important ! Do not forget to init the contentMode :
``` swift let myImage = UIImageViewModeScaleAspect(frame: CGRect(x: 0, y: 100, width: 200, height: 100)) myImage.contentMode = .scaleAspectFill // Add the first contentMode myImage.image = UIImage(named: "Octocat") view.addSubview(myImage) ```For convert UIViewContentModeScaleAspectFill to UIViewContentModeScaleAspectFit :
``` swift myImage.animate( .fit, frame: CGRect(x: 0, y: 0, width: 200, height: 200), duration: 0.4) ```For convert UIViewContentModeScaleAspectFit to UIViewContentModeScaleAspectFill :
``` swift myImage.animate( .fill, frame: CGRect(x: 0, y: 0, width: 200, height: 200), duration: 0.4) ```For convert UIViewContentModeScaleAspectFill to UIViewContentModeScaleAspectFit :
``` swift myImage.initialeState(.fit, newFrame: CGRect(x: 0, y: 100, width: 200, height: 100))UIView.animate(withDuration: 0,4, delay: 0, options: .allowAnimatedContent, animations: { // // Others Animation // myImage.transitionState(.fit) }, completion: { (finished) in myImage.endState(.fit) })
<p>For convert UIViewContentModeScaleAspectFit to UIViewContentModeScaleAspectFill :</p>
``` swift
myImage.initialeState(.fill, newFrame: CGRect(x: 0, y: 100, width: 200, height: 100))
UIView.animate(withDuration: 0,4, delay: 0, options: .allowAnimatedContent, animations: {
//
// Others Animation
//
myImage.transitionState(.fill)
}, completion: { (finished) in
myImage.endState(.fill)
})