Reputation: 94
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.
Upvotes: 3
Views: 136
Reputation: 645
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
}
Upvotes: 3