UIImageViewModeScaleAspect 2.0

UIImageViewModeScaleAspect 2.0

测试已测试
语言语言 SwiftSwift
许可证 MIT
发布日期最后发布日期2016年10月
SPM支持SPM

Vivien Cormier维护。



  • 作者:
  • Vivien Cormier

UIImageViewModeScaleAspect (2.0)

在两种内容模式(UIViewContentModeScaleAspectFill / UIViewContentModeScaleAspectFit)之间创建UIImageView动画

我的网站 - My WebSite - 我的Twitter

兼容Swift 3.0

屏幕截图 & 演示视频

要观看演示视频,请点击此处

ScreenShot Demo Video ScreenShot Demo Video

如何开始

使用Pod(或者下载并将“UIImageViewModeScaleAspect.swift”添加到您的xcode项目中。)

pod 'UIImageViewModeScaleAspect'

初始化UIImageViewModeScaleAspect。重要!不要忘记初始化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)

自动动画

将UIViewContentModeScaleAspectFill转换为UIViewContentModeScaleAspectFit

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

将UIViewContentModeScaleAspectFit转换为UIViewContentModeScaleAspectFill

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

手动动画

将UIViewContentModeScaleAspectFill转换为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)
})

将UIViewContentModeScaleAspectFit转换为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)
})