【发布时间】:2015-03-20 22:38:00
【问题描述】:
我有一个容器视图,我最初希望它位于屏幕底部。这应该很容易,但我似乎缺少一些基本的东西。我以前做过类似的事情,方法是将控件从屏幕左侧移开:
control.center.x -= view.bounds.width
我有一个非常简单的故事板设置:
我的视图控制器看起来像这样:
class ViewController: UIViewController {
@IBOutlet var containerView: UIView!
override func viewWillAppear(animated: Bool) {
super.viewWillAppear(animated)
containerView.center.y += view.bounds.height
}
}
运行时,容器视图正好在故事板中显示的位置,并且不在屏幕外。即使将 containerView 的 center.y 设置为特定值(例如 containerView.center.y = 50)也无济于事。我可以让它在屏幕上炫耀的唯一方法是在 viewDidAppear 中添加动画:
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
UIView.animateWithDuration(0, animations: {self.containerView.center.y += self.view.bounds.height})
}
但这似乎只是一种解决方法,而不是正确的方法。我已经处理了几个小时,阅读博客,阅读其他 Stackoverflow 问题,但我找不到解决方案。我对容器没有约束,尽管我确实用约束对其进行了测试,但这并没有什么不同。任何帮助表示赞赏。
【问题讨论】:
标签: ios swift uiview uiviewanimation