简体   繁体   English

Interface Builder中“查看为”的问题

[英]Issues with 'View as' in Interface Builder

I'm currently having issues when I try to use the 'View as' option in interface builder. 当我尝试在界面生成器中使用“查看方式”选项时,我目前遇到问题。

When select 'View as' for, for example, iPhone 8 Plus, all the views constraints update so that it looks fine on iPhone 8 Plus in interface builder, but subviews of UITableViewCells do not update in interface builder. 例如,当为iPhone 8 Plus选择“视图为”时,所有视图约束都会更新,以便在界面构建器中的iPhone 8 Plus上看起来很好,但是UITableViewCells的子视图不会在界面构建器中更新。 This can be seen in the screenshots below. 可以在下面的屏幕截图中看到。

Viewing as iPhone 8 Plus, switched from viewing as iPhone X 以iPhone 8 Plus观看,已从以iPhone X观看切换

Viewing as iPhone X, switched from viewing as iPhone 8 Plus 以iPhone X观看,已从以iPhone 8 Plus观看

Normally this wouldn't really bother me, as it builds and all constraints are updated, but when I build the app, for some reason a CAGradientLayer I have setup on the master subview of the UITableViewCell does not update to these constraints, and keeps the constraints of the previous 'View as' option. 通常,这不会真的困扰我,因为它会构建并更新所有约束,但是当我构建应用程序时,由于某种原因,我在UITableViewCell的主子视图上设置的CAGradientLayer不会更新为这些约束,并保持以前的“查看方式”选项的约束。

CAGradientLayer constraint issues CAGradientLayer约束问题

I have tried to override layoutSublayers(of: CALayer) and then update the width of the CALayer to update the new width of the UIView, but this does not work as the frame of the UIView is not updating to reflect the updated constraints. 我试图覆盖layoutSublayers(of: CALayer) ,然后更新layoutSublayers(of: CALayer)的宽度以更新UIView的新宽度,但这不起作用,因为UIView的框架未更新以反映更新的约束。

Is there any way I can get the width of the UIView with the constraints applied? 有什么办法可以应用约束来获取UIView的宽度? Or is there a fix I can apply in Xcode that would fix this. 还是有我可以在Xcode中应用的修复程序来解决此问题。

Many thanks, 非常感谢,

-William -威廉

Update the frame of the gradient inside layoutSubviews 更新layoutSubviews内部渐变的框架

override func layoutSubviews() 
  super.layoutSubviews()
  // set the frame of the gradient here 
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM