【问题标题】:The frame of the UIView is changed after be flippedUIView 的框架被翻转后发生变化
【发布时间】:2017-02-04 09:39:31
【问题描述】:

我使用 UIView.transition 方法在 2 个视图之间翻转,但之后,两个视图的框架都发生了变化。

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

我怎么了?感谢您的帮助。

【问题讨论】:

    标签: ios uiview swift3 uiviewanimationtransition


    【解决方案1】:

    我解决了同样的问题。问题是当我们使用从视图 A 到视图 B 的翻转过渡时,我们失去了它的约束。

    解决方案:

    将两个视图(即 frontView 和 behindView)放入 parentView 并使用:

    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
    
    }
    

    【讨论】:

    • 感谢@maddy的语法:)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多