-2

Here is the example. example

I want to learn how logo in the example moves VC1 to VC2 here. Can you make a simple example? İt would be anything.

Please, do not recommend me third party.

rmaddy
  • 314,917
  • 42
  • 532
  • 579
John
  • 675
  • 1
  • 7
  • 16
  • Too broad, and custom transition animations have been discussed here many times and have been explained in many tutorials and Apple videos. Please do this sort of general background work yourself. – matt Mar 13 '18 at 16:32
  • Probable duplicate of https://stackoverflow.com/questions/33161692/sharing-an-image-between-two-viewcontrollers-during-a-transition-animation – matt Mar 13 '18 at 16:34
  • @matt I know but I don't know hot to work with snapshot. I don't find enough article on web. – John Mar 13 '18 at 16:52
  • that is the [native Apple Docs](https://developer.apple.com/documentation/uikit/uiviewcontroller) about the topic. – holex Mar 13 '18 at 17:12
  • @matt the link you entered answer the question? The guy just say how to do it without any code. Also there people want to have code anyways. – John Mar 13 '18 at 17:30

1 Answers1

2

I wrote a blog post some time ago about how to make custom transitions and animations although this is more like a guide for the App Store it could be used for any type of transition animation.

https://medium.com/@eric.dockery283/custom-view-transitions-like-the-new-app-store-a2a1181229b6

Things to look into would be UIViewControllerAnimatedTransitioning

In summary you will need 2 view controllers your login view controller and your end state view controller for the animation. You will use UIViewControllerAnimatedTransitioning to handle the transition from one view controller to another. My example is:

import UIKit
class TransitionAnimator: NSObject, UIViewControllerAnimatedTransitioning {
  let durationExpanding = 0.75
  let durationClosing = 0.5
  var presenting = true
  var originFrame = CGRect.zero
  var dismissCompletion: (()->Void)?
  func transitionDuration(using transitionContext: UIViewControllerContextTransitioning?) -> TimeInterval {
   if presenting {
    return durationExpanding
   }
   return durationClosing
  }
  func animateTransition(using transitionContext: UIViewControllerContextTransitioning) {
   let containerView = transitionContext.containerView
   guard let toView = transitionContext.view(forKey: .to), let detailView = presenting ? toView: transitionContext.view(forKey: .from) else {
      return
   }
   let initialFrame = presenting ? originFrame : detailView.frame
   let finalFrame = presenting ? detailView.frame : originFrame
   let xScaleFactor = presenting ? initialFrame.width / finalFrame.width : finalFrame.width / initialFrame.width
   let yScaleFactor = presenting ? initialFrame.height / finalFrame.height : finalFrame.height / initialFrame.height
   let scaleTransform = CGAffineTransform(scaleX: xScaleFactor,
y: yScaleFactor)
   if presenting {
     detailView.transform = scaleTransform
     detailView.center = CGPoint( x: initialFrame.midX, y: initialFrame.midY)
     detailView.clipsToBounds = true
   }
   containerView.addSubview(toView)
   containerView.bringSubview(toFront: detailView)
   if presenting {
    //update opening animation
    UIView.animate(withDuration: durationExpanding, delay:0.0,
usingSpringWithDamping: 1.0, initialSpringVelocity: 0.0, //gives it some bounce to make the transition look neater than if you have defaults
    animations: {
        detailView.transform = CGAffineTransform.identity
        detailView.center = CGPoint(x: finalFrame.midX, y: finalFrame.midY)
},
    completion:{_ in
        transitionContext.completeTransition(true)
   }
   )
} else {
//update closing animation
     UIView.animate(withDuration: durationClosing, delay:0.0, options: .curveLinear,
      animations: {
       detailView.transform = scaleTransform
       detailView.center = CGPoint(x: finalFrame.midX, y: finalFrame.midY)
},
  completion:{_ in
    if !self.presenting {
      self.dismissCompletion?()
     }
     transitionContext.completeTransition(true)
   }
  )
  }
 }
}

You will need to set up your transitioning delegate in your login view controller:

extension ViewController: UIViewControllerTransitioningDelegate {
   func animationController(forPresented presented: UIViewController, presenting: UIViewController, source: UIViewController) -> UIViewControllerAnimatedTransitioning? {
     guard let originFrame = selectedCell.superview?.convert(selectedCell.frame, to: nil) else {
      return transition
     }
    transition.originFrame = originFrame
    transition.presenting = true
    selectedCell.isHidden = true
    return transition
  }
    func animationController(forDismissed dismissed: UIViewController) -> UIViewControllerAnimatedTransitioning? {
       transition.presenting = false
       return transition
    }
}

This should allow you to customize your views/animations the way that you need.

Another helpful link: https://www.raywenderlich.com/146692/ios-animation-tutorial-custom-view-controller-presentation-transitions-2

Lunarchaos42
  • 253
  • 4
  • 13
  • 1
    Link-only answers are not very useful. An answer should include at least a basic summary. An answer must remain useful even if the link goes bad. – rmaddy Mar 13 '18 at 17:19
  • @rmaddy you are right. On the web, people say that I need two views and a snapshot view for this custom transtion. But There is not any example out there showing how to do. Worst is question downvoted. – John Mar 13 '18 at 17:26
  • 1
    Updated the answer to use more information instead of just linking to my blog post. – Lunarchaos42 Mar 13 '18 at 20:03