2017-02-04 26 views
3

我使用UIView.transition方法在2個視圖之間翻轉,但在此之後,兩個視圖的框架都被更改了。UIView的框架在翻轉後被更改

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 
     } 
    }) 
} 

我的錯誤是什麼?感謝您的幫助。

image

回答

2

我解決了同樣的問題。問題是,當我們使用從視圖中翻動過渡到視圖B,我們失去了約束。

解決方案:

放入parentView兩個視圖中(即FrontView中和behindView)和使用:

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

實施例:

@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 

} 
+0

感謝名單@maddy與所述語法:) –