Search code examples
iosanimationuiviewflipanimatewithduration

How to animate a particular view in View controller


I have a view (View X) in a View Controller and on completion of some task I want to flip that view and show a image view on that location along with flip animation. I am using this code right now but this animates the whole view controller.

[UIView transitionFromView:_viewVerification // view to hide
                    toView:_imageviewDone // image to display
                  duration:0.5
                   options:UIViewAnimationOptionTransitionFlipFromRight
                completion:nil];

Any idea how can i implement this thing?

Thanks.


Solution

  • front and back are two views which will be contained in card view (Parent View of front and back view which will be flipped) . Now when View controller launches one of the view (either back or front) will be hidden . You can contain imageView in one of the view and you can make _viewVerification as any of the other view

    if(self.back.hidden) {
            self.front.hidden = true
            self.back.hidden = false
            UIView.transitionWithView(cardView, duration: 1.0, options: UIViewAnimationOptions.TransitionFlipFromRight, animations: {
    
                }, completion: nil)
            } 
    else {
            self.front.hidden = false
            self.back.hidden = true
            UIView.transitionWithView(cardView, duration: 1.0, options: UIViewAnimationOptions.TransitionFlipFromLeft    , animations: {
    
                }, completion: nil)
    
    
        }