2017-02-04 59 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与所述语法:) –