【发布时间】:2020-03-25 10:34:47
【问题描述】:
我正在开发一项功能,该功能将在屏幕底部为UIView 设置动画,以告诉用户他们的数据已保存。但是,它在 iPhone 11 Pro Max 上的出现位置与在 iPhone X 上不同。
iPhone 11 Pro Max(这是我想要的样子):
但在 iPhone X 上:
我可能应该注意到我在情节提要上创建了视图,并有一个@IBOutlet 连接到它。在故事板上,它位于您在顶部屏幕截图中看到的位置。我没有对其施加任何限制。其余的在代码中完成。
动画的代码很简单:
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
savedView.center.y += view.bounds.height // start with it off the screen
savedView.center.x = (view.bounds.width / 2)
}
override func viewDidAppear(_ animated: Bool) {
super.viewWillAppear(true)
// animate it onto the screen
UIView.animate(withDuration: 0.5, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 0.0, options: [], animations: {
self.savedView.center.y -= self.view.bounds.height <-- the problem must be here
}, completion: nil)
}
我认为这可能是由于设备尺寸等级不同,但所有 iPhone 都是“常规”高度,所以我不认为是这样。
如何让这个视图在所有设备上都位于相同的位置(相对于屏幕底部)?
【问题讨论】:
标签: ios swift uiview uiviewanimation