maitree solanki maitree solanki - 5 months ago 31
iOS Question

animation while changing view swift

I am new to swift.I want to do animation while changing view from one view-controller to other view-controller.i am using prepareForSegue: method on button click, i have searched lot but did not find any solution do anyone have solution for this?

// call following code in the method where you want to add animation effect.

func buttonClicked(sender: UIButton){

  let transition = CATransition()
  transition.duration = 0.5
  transition.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut)
  transition.type = kCATransitionPush
  transition.subtype = kCATransitionFromRight
  self.navigationController?.view.layer.addAnimation(transition, forKey: nil)
  self.navigationController?.pushViewController(vc!, animated: true)


// you can vary the duration of transition according to your convenience 

// here transition.type are types of animation which you want to add on view. now we are pushing view so used push type. if want, you can google it for more types.

// subtype will decide the direction on animation.