Xcode 9 beta 中的“API 错误:(null) 返回 0 宽度,假设 UIViewNoIntrinsicMetric”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/45256811/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 10:08:57  来源:igfitidea点击:

"API error: (null) returned 0 width, assuming UIViewNoIntrinsicMetric" in Xcode 9 beta

xcodexcode9-betaxcode9

提问by IceApinan

I'm working on several projects and it happens the same error.

我正在处理几个项目,但发生了同样的错误。

I still can't figure out what's causing it. Is it the problem with my code or Xcode 9 beta?

我仍然无法弄清楚是什么原因造成的。是我的代码还是 Xcode 9 beta 的问题?

MyApp[22724:4000717] API error: (null) returned 0 width, assuming UIViewNoIntrinsicMetric

MyApp[22724:4000717] API 错误:(null) 返回 0 宽度,假设 UIViewNoIntrinsicMetric

回答by Edison

@rmaddy correctly linked to another SO answer however there are other possibilities related to auto layout practices.

@rmaddy 正确链接到另一个 SO 答案,但是还有其他与自动布局实践相关的可能性。

The message could also be related to auto layout implementations and unique constraints defined in your project. It seems that this message normally does not appear when using a real device.

该消息还可能与项目中定义的自动布局实现和唯一约束有关。似乎在使用真实设备时通常不会出现此消息。

UIKit framework -> UIView API Global VariableUIViewNoIntrinsicMetric

UIKit 框架 -> UIView API 全局变量UIViewNoIntrinsicMetric

UIViewNoIntrinsicMetricThe absence of an intrinsic metric for a given numeric view property.

UIViewNoIntrinsicMetric给定数字视图属性缺少内在指标。

UIView Implementation Practices

UIView 实现实践

Every UIView subclass should implement the intrinsicContentSizeand return the size that it thinks is suitable for it. For example:

每个 UIView 子类都应该实现internalContentSize并返回它认为适合它的大小。例如:

  • If you know the UIView's width you use return CGSizeMake(200, 50).
  • If you don't know how wide the view is you would use UIViewNoIntrinsicMetricinstead of the width. return CGSizeMake(UIViewNoIntrinsicMetric, 50)
  • 如果您知道 UIView 的宽度,请使用 return CGSizeMake(200, 50)。
  • 如果您不知道视图有多宽,您将使用UIViewNoIntrinsicMetric而不是宽度。return CGSizeMake(UIViewNoIntrinsicMetric, 50)

UIView base implementation of updateConstraintswill call the intrinsicContentSizeand it will use the content size returned from it to add constraints to the UIView.

UIView 的基本实现updateConstraints将调用内部内容大小,并将使用从它返回的内容大小向 UIView 添加约束。

UIView API PropertyintrinsicContentSize

UIView API 属性intrinsicContentSize

intrinsicContentSizeThe natural size for the receiving view, considering only properties of the view itself.

intrinsicContentSize接收视图的自然大小,仅考虑视图本身的属性。

Custom views typically have content that they display of which the layout system is unaware. Setting this property allows a custom view to communicate to the layout system what size it would like to be based on its content. This intrinsic size must be independent of the content frame, because there's no way to dynamically communicate a changed width to the layout system based on a changed height, for example. If a custom view has no intrinsic size for a given dimension, it can use UIViewNoIntrinsicMetricfor that dimension.

自定义视图通常具有布局系统不知道的内容。设置此属性允许自定义视图根据其内容与布局系统通信它想要的大小。这种固有大小必须独立于内容框架,因为例如,无法根据更改的高度将更改的宽度动态传达给布局系统。如果自定义视图没有给定维度的固有大小,则它可以 UIViewNoIntrinsicMetric用于该维度。

Conclusion

结论

Xcode error:

Xcode 错误:

returned 0 width, assuming UIViewNoIntrinsicMetric

返回 0 宽度,假设 UIViewNoIntrinsicMetric

Therefore we can get an idea that Xcode is assuming a UIViewNoIntrinsicMetricsize since a width size of 0 was returned by some UIView in your project.

因此,我们可以了解到 Xcode 假定UIViewNoIntrinsicMetric大小,因为您项目中的某些 UIView 返回了宽度大小 0。

If you are still getting the message when deploying on a real device then I'd pay extra attention to your layout constraints.

如果您在实际设备上部署时仍然收到消息,那么我会特别注意您的布局约束。

回答by tanzeel khalid

I have applied many solutions but found nothing except downgrading my "WKWebView" to "UIWebView" having two different ways: 1. Just add this to your config.xml

我已经应用了许多解决方案,但除了通过两种不同的方式将我的“WKWebView”降级到“UIWebView”之外,一无所获: 1. 只需将其添加到您的 config.xml

<preference name="CordovaWebViewEngine" value="CDVUIWebViewEngine"/>

OR

或者

  1. Uninstall the Ionic WebView plugin with this command.
  1. 使用此命令卸载 Ionic WebView 插件。

ionic cordova plugin remove cordova cordova-plugin-ionic-webview --save

离子cordova插件删除cordova cordova-plugin-ionic-webview --save

Here is the link:

链接在这里:

https://ionicframework.com/docs/wkwebview/#downgrading-to-uiwebview

https://ionicframework.com/docs/wkwebview/#downgrading-to-uiwebview