3

I have a weird issue with swift. I am trying to flip two views, not the whole screen but it flips the whole screen.

It has been asked before on here but no answer:

flip animation in swift flips whole view not subviews

This is the references to the views I have (I have confirmed they only take up part of the screen):

@IBOutlet var frontview: UIView!
@IBOutlet var backview: UIView!

And this is my code for flipping:

func flipCard() { 

   if (showingBack) {
        UIView.transitionFromView(backview, toView: frontview, duration: 1, options: UIViewAnimationOptions.TransitionFlipFromRight, completion: nil)
        showingBack = false
    } else {
        UIView.transitionFromView(frontview, toView: backview, duration: 1, options: UIViewAnimationOptions.TransitionFlipFromLeft, completion: nil)
        showingBack = true
    }       
}

Thanks for your help

Community
  • 1
  • 1
Nicholas Muir
  • 2,897
  • 8
  • 39
  • 89

2 Answers2

1

What happens when you call UIView.transitionFromView(backView, toView: frontView ... is it flips the parent of those two views. Presumably the parent in your case is the root view of the ViewController, so to get it to flip just those views instead of the "whole screen" you would just need to embed both backView and frontView in another view.

There's more details in this article.

Workshed
  • 236
  • 1
  • 8
0

Try This example. I think you are looking something like this. instead of imageView try UIView in your case.

Bhautik Ziniya
  • 1,554
  • 12
  • 19
  • Thanks but this is the example i used to make my code. It is exactly the same and will have the same issue. – Nicholas Muir Aug 16 '16 at 11:49
  • I think the issue is with the IBOutlets. try making your view programmatically if satisfies your requirement. i have tried it. and it is working fine. with creating views programmatically . – Bhautik Ziniya Aug 16 '16 at 11:52