我在 self.view 中有两个 View ,它们是容器 View (通过 Storyboard:每个 View 在 viewDidLoad 中都有一个嵌入的 segue,它加载了各自的 subview Controller )。它们称为 self.leftPane 和 self.rightPane。我正在使用自动布局。
我想为 self.leftPane 的位置变化设置动画,因为它从 x=0 移动到 x=(negative something)。我基本上是想以一种简单的方式在左侧制作一个汉堡包菜单...
@IBOutlet weak var leftPane: UIView! // has child view controller embedded
@IBOutlet weak var rightPane: UIView! // has child view controller embedded
// in/after viewDidAppear
self.leftPaneLeftConstraint.constant = 0 - self.leftPane.frame.size.width + 20.0
UIView.transition(with: self.leftPane, duration: 1.0, options: [], animations: {
self.leftPane.layoutIfNeeded()
}, completion: { (finished) in
self.leftPaneIsFull = false
})
问题是没有动画——它只是跳跃。 我尝试过使用不同 View 和不同 UIView.animate 风格的 UIView.transition,所有这些都具有相同的效果(没有实际的动画)。
我错过了什么?谢谢!
最佳答案
你应该使用 UIView.animate 而不是 UIView.transition。我写下了代码示例。你试试这个代码吗?
@IBOutlet weak var leftPane: UIView! // has child view controller
embedded
@IBOutlet weak var rightPane: UIView! // has child view controller embedded
// in/after viewDidAppear
UIView.animate(withDuration: 1.0, animations: {
self.leftPaneLeftConstraint.constant = 0 - self.leftPane.frame.size.width + 20.0
self.view.layoutIfNeeded()
}, completion: { (success) -> Void in
//You can write something you want
})
}
})
好好享受吧:)
关于ios - 无法为具有 subview Controller 的两个容器 UIView 的位置更改设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43267508/