我有一个 UIViewController
,我在 ViewDidLoad
中设置了它的大小,如下所示:
//Setting view's frame
let width = UIScreen.main.bounds.size.width - 10
let height = (43 * UIScreen.main.bounds.height) / 100 //%43 of the screen
self.view.frame = CGRect(x: 5, y: 80, width: width, height: height)
它工作得很好,直到我尝试呈现另一个这样的 ViewController
:
//Presenting AutoCompleteVC
self.autocompleteVC = GMSAutocompleteViewController()
self.autocompleteVC.delegate = self
self.present(self.autocompleteVC, animated: true, completion: nil)
在我关闭此 View (self.autocompleteVC.dismiss(animated: true, succession: nil)
) 后,第一个 ViewController
View 的框架更改为全屏的框架。
知道如何修复它吗?
谢谢!
最佳答案
在viewWillLayoutSubviews
中设置框架。那时框架已经已知。像这样:
public override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
//Setting view's frame
let width = UIScreen.main.bounds.size.width - 10
let height = (43 * UIScreen.main.bounds.height) / 100 //%43 of the screen
self.view.frame = CGRect(x: 5, y: 80, width: width, height: height)
}
关于ios - UIViewController View 的框架在呈现后发生变化(viewController : animated: completion: ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43410463/