Search code examples
ios5rubymotion

How to do a sliding transition in RubyMotion?


I've been looking at the different examples of loading a screen - is there a way to insert a transition screen (sliding) when the a tap is detected? Currently UIImage.imageNamed loads up the next graphic instantly - how to make it slide?

def viewDidLoad
  view.image = UIImage.imageNamed('welcome.png')

  view.userInteractionEnabled = true
  recognizer = UITapGestureRecognizer.alloc.initWithTarget(self, action:'nextScreen')
  view.addGestureRecognizer(recognizer)
end

Solution

  • Here is a nextScreen method that should do what you want. With the animation setup, the view.image = ... line will slide the image in from the right.

    def nextScreen
      animation = CATransition.animation
      animation.duration = 0.5
      animation.type = KCATransitionMoveIn
      animation.subtype = KCATransitionFromRight
      view.layer.addAnimation(animation, forKey:'imageTransition')
      view.image = UIImage.imageNamed('pic2.png')
    end
    

    Source: https://stackoverflow.com/a/5057691/424300