【发布时间】:2020-05-21 04:18:57
【问题描述】:
UIView 的视差效果根本不起作用。我需要像 iPhone 倾斜上的移动背景图像(伪 3D)。
let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: .TiltAlongHorizontalAxis)
horizontalMotionEffect.minimumRelativeValue = -50
horizontalMotionEffect.maximumRelativeValue = 50
let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .TiltAlongVerticalAxis)
verticalMotionEffect.minimumRelativeValue = -50
verticalMotionEffect.maximumRelativeValue = 50
let motionEffectGroup = UIMotionEffectGroup()
motionEffectGroup.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
imageView.addMotionEffect(motionEffectGroup)
我已尝试使用此代码。我读过https://www.hackingwithswift.com/example-code/uikit/how-to-create-a-parallax-effect-in-uikit,但我的imageView 保持不变。
我正在使用 Xcode 11、iOS 13。
【问题讨论】:
-
imageView是您将效果应用于表格或集合视图的一部分吗?如果是这样,您可能需要查看:stackoverflow.com/questions/19319722/… -
不,它只是普通的 UIImageView,受限于 superview
标签: ios swift uikit parallax uimotioneffect