Swift3 淡入/淡出或平滑过渡 UIImageView animationImages

Posted

技术标签:

【中文标题】Swift3 淡入/淡出或平滑过渡 UIImageView animationImages【英文标题】:Swift3 Fade in/Fade out or Smooth transition UIImageView animationImages 【发布时间】:2017-04-01 21:51:06 【问题描述】:

我正在尝试制作图片幻灯片

在 UIImageView (Swift3) 中为动画图像添加平滑过渡的最佳方法是什么

这里是我的幻灯片代码:

        DispatchQueue.main.async 
                imageView.animationImages = activeImages
                imageView.clipsToBounds = true
                imageView.animationDuration = (1.0 * Double(activeImages.count))
                imageView.animationRepeatCount = Int.max
                imageView.startAnimating()
         

【问题讨论】:

【参考方案1】:

使用UIVIew.animate 块和两个UIImageViews 进行转换,它们很常用并且可以生成非常干净的代码。

UIView.animate(withDuration: 0.3,
               delay: 0,
               options: .curveEaseInOut, //just an example, check UIViewAnimationOptions
               animations: 
      self.image1.alpha = 0
      self.image2.alpha = 1
)

【讨论】:

我想要一个无限重复的幻灯片,包含 20 张图片,我认为 UIVIew.animate 更适合临时动画,不是吗? 这个响应不是用户想要在这里解决的

以上是关于Swift3 淡入/淡出或平滑过渡 UIImageView animationImages的主要内容,如果未能解决你的问题,请参考以下文章