我注意到
Xcode 9有些奇怪.当我在我的主故事板上并且我更改所选设备以查看适当格式的视图控制器时,我注意到我在viewDidLoad上的tableview的宽度是错误的,如果故事板上选定的设备与我部署的设备不同.我已经完成了测试,似乎在故事板上选择了所选设备的布局.
@H_404_8@
有没有人已经遇到过这个问题?@H_404_8@
此问题也出现在Xcode的beta版本9.1中@H_404_8@
解决方法
当我尝试将遮罩应用到视图的图层以便在UITableViewCell内圆角时,我注意到了同样的问题.
This answer为我做了诀窍.
@H_404_8@
在layoutSubviews()中,在运行时需要真实大小的任何视图上调用layoutIfNeeded().对于我的用法,它看起来像这样:@H_404_8@
@H_404_8@
override func layoutSubviews() { super.layoutSubviews() print("cardView frame: \(cardView.frame)") // Storyboard size cardView.layoutIfNeeded() print("cardView frame: \(cardView.frame)") // Runtime device size // Perform your layout here. }
我希望这有帮助!@H_404_8@