iOS 7 parallax effect in my view controller

前端 未结 9 2034
终归单人心
终归单人心 2020-11-30 16:27

I\'m developing an app for iOS 7 in Objective-C. I\'ve got a screen in my app with a few buttons and a pretty background image. (It\'s a simple xib with UIButtons

9条回答
  •  自闭症患者
    2020-11-30 16:47

    Swift translation:

    // Set vertical effect
    let verticalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.y", type: .TiltAlongVerticalAxis)
    verticalMotionEffect.minimumRelativeValue = -value
    verticalMotionEffect.maximumRelativeValue = value
    
    // Set vertical effect
    let horizontalMotionEffect = UIInterpolatingMotionEffect(keyPath: "center.x", type: .TiltAlongHorizontalAxis)
    verticalMotionEffect.minimumRelativeValue = -value
    verticalMotionEffect.maximumRelativeValue = value
    
    let group = UIMotionEffectGroup()
    group.motionEffects = [horizontalMotionEffect, verticalMotionEffect]
    self.motionEffect = group
    self.addMotionEffect(group)
    

提交回复
热议问题