我正在使用一项功能,该功能将从屏幕底部向上显示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的高度都是'常规'的,所以我不这么认为。
如何在所有设备上使该视图最终显示在相同位置(相对于屏幕底部)?
我正在使用一项功能,该功能将从屏幕底部开始为UIView设置动画,以告诉用户其数据已保存。但是,它不会在iPhone 11 Pro Max上出现在与它相同的位置...
为了在所有设备上将视图放置在相同位置
我能够弄清楚。