Latest 2.0
Homepage https://github.com/VivienCormier/UIImageViewModeScaleAspect
License MIT
Platforms ios 8.0, requires ARC
Authors

Twitter: @VivienCormier
Build Status
codecov

UIImageViewModeScaleAspect (2.0)

Create animation of a UIImageView between two contentMode ( UIViewContentModeScaleAspectFill / UIViewContentModeScaleAspectFit )

My WebSiteMy Twitter

Compatible Swift 3.0

Screenshot & Demo Video

To see a demo video, click here

ScreenShot Demo Video
ScreenShot Demo Video

How To Get Started

Use Pod (or download and add “UIImageViewModeScaleAspect.swift” in your xcodeprojet.) :

pod 'UIImageViewModeScaleAspect'

Init the UIImageViewModeScaleAspect. Important ! Do not forget to init the contentMode :

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)

Automatic animation

For convert UIViewContentModeScaleAspectFill to UIViewContentModeScaleAspectFit :

myImage.animate( .fit, frame: CGRect(x: 0, y: 0, width: 200, height: 200), duration: 0.4)

For convert UIViewContentModeScaleAspectFit to UIViewContentModeScaleAspectFill :

myImage.animate( .fill, frame: CGRect(x: 0, y: 0, width: 200, height: 200), duration: 0.4)

Manual animation

For convert UIViewContentModeScaleAspectFill to UIViewContentModeScaleAspectFit :

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)
})

For convert UIViewContentModeScaleAspectFit to UIViewContentModeScaleAspectFill :

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)
})

Latest podspec

{
    "name": "UIImageViewModeScaleAspect",
    "version": "2.0",
    "summary": "Create animation of a UIImageView between twice contentMode ( UIViewContentModeScaleAspectFill / UIViewContentModeScaleAspectFit ).",
    "homepage": "https://github.com/VivienCormier/UIImageViewModeScaleAspect",
    "authors": {
        "Vivien Cormier": "[email protected]"
    },
    "source": {
        "git": "https://github.com/VivienCormier/UIImageViewModeScaleAspect.git",
        "tag": "2.0"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "UIImageViewModeScaleAspect/UIImageViewModeScaleAspect.swift",
    "license": "MIT",
    "requires_arc": true
}

Pin It on Pinterest

Share This