【问题标题】:Add parallax effect when scrolling through images in UIScrollView在 UIScrollView 中滚动图像时添加视差效果
【发布时间】:2023-03-19 04:55:01
【问题描述】:

我一直在制作一个启用了分页的 UIScrollView,它像普通 UICollectionView 一样滚动浏览照片。我希望图像视图在滚动时具有视差效果。

我想在滚动时产生这样的效果 https://github.com/MP0w/MPParallaxCollection/blob/master/img/inaction.gif

任何帮助 提前致谢 雅利安人

【问题讨论】:

标签: ios swift uiscrollview


【解决方案1】:

您在跳板应用程序中获得的视差效果是在 iOS 7 中引入的,并使用名为 UIMotionEffect 的类实现。

在 Google 上快速搜索 Parallax 和 UIMotionEffect,我找到了几十个教程结果。

基本技术包括使用init(keyPath: String, type: UIInterpolatingMotionEffectType) 方法创建 UIMotionEffect 的某个子类的实例。 keyPath 将是您希望为其提供效果的动画视图的属性,type: 参数指定何时应用效果。

【讨论】:

  • 嗨,斯科特,我已经编辑了答案,以说明我到底想要什么,就像我使用 UIInterpolatingMotion 一样,当我实际倾斜手机时它会产生视差效果。
猜你喜欢
  • 2013-01-20
  • 2014-04-07
  • 2019-10-17
  • 1970-01-01
  • 1970-01-01
  • 2019-02-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多