UIInterpolatingMotionEffect.swift 963 B

12345678910111213141516171819202122232425262728293031
  1. //
  2. // UIInterpolatingMotionEffect.swift
  3. // Mastodon
  4. //
  5. // Created by MainasuK Cirno on 2021-3-2.
  6. //
  7. import UIKit
  8. extension UIInterpolatingMotionEffect {
  9. static func motionEffect(
  10. minX: CGFloat,
  11. maxX: CGFloat,
  12. minY: CGFloat,
  13. maxY: CGFloat
  14. ) -> UIMotionEffectGroup {
  15. let motionEffectX = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.x", type: .tiltAlongHorizontalAxis)
  16. motionEffectX.minimumRelativeValue = minX
  17. motionEffectX.maximumRelativeValue = maxX
  18. let motionEffectY = UIInterpolatingMotionEffect(keyPath: "layer.transform.translation.y", type: .tiltAlongVerticalAxis)
  19. motionEffectY.minimumRelativeValue = minY
  20. motionEffectY.maximumRelativeValue = maxY
  21. let motionEffectGroup = UIMotionEffectGroup()
  22. motionEffectGroup.motionEffects = [motionEffectX, motionEffectY]
  23. return motionEffectGroup
  24. }
  25. }