3

I used UIView.transition method to flip between 2 views, but after that, the frame of both views was changed.

if isFront {
    UIView.transition(from: frontView, to: behindView, duration: 0.5, options: .transitionFlipFromRight,completion: { (finished) in
        if finished {
            self.isFront = false
        }
    })
} else {
    UIView .transition(from: behindView, to: frontView, duration: 0.5, options: .transitionFlipFromLeft, completion: { (finished) in
        if finished {
            self.isFront = true
        }
    })
}

What is my wrong? Thanks for your helps.

image

Incinerator
  • 2,589
  • 3
  • 23
  • 30
Trung Hoang
  • 94
  • 11

1 Answers1

3

I solved the same issue. The problem is that when we use flip transition from view A to view B we lose its constraints.

Solution:

Put both views (i.e frontView and behindView) into a parentView and use:

UIView.transition(with: scroller, duration: 0.5, options: .transitionFlipFromLeft,animations: { () -> Void in}, completion: { _ in })

Example:

 @IBAction func FlipButtonAction(_ sender: Any) {
    if(front){            
        frontView.isHidden = true
        behindView.isHidden = false

        UIView.transition(with: parentView, duration: 0.5, options: .transitionFlipFromLeft,animations: { () -> Void in}, completion: { _ in })

        print("1")
    }else{
        frontView.isHidden = false
        behindView.isHidden = true

        UIView.transition(with: parentView, duration: 0.5, options: .transitionFlipFromLeft,animations: { () -> Void in}, completion: { _ in })
        print("2")

    }
    front = !front

}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Amit Sharma
  • 645
  • 5
  • 13