简体   繁体   English

在缩放的CGRect iOS上显示UIView

[英]Display UIView on scaled CGRect iOS

I am using the AVMetaData API to extract the bounds of an AVMetadataFaceObject. 我正在使用AVMetaData API提取AVMetadataFaceObject的界限。 When printed to the console, this CGRect has the following values: bounds={0.2,0.3 0.4x0.5} . 当打印到控制台时,此CGRect具有以下值: bounds={0.2,0.3 0.4x0.5} I'm having a fair amount of trouble mapping this to a UIView that displays over the face. 我在将其映射到显示在脸上的UIView时遇到了很多麻烦。 I can hard-code in some conversion values for my specific screen to get it to crudely be in the right spot, but I would like a solution that displays a UIView over the face shown in my previewView on any screen size. 我可以为特定的屏幕硬编码一些转换值,以使其大致位于正确的位置,但是我想要一个解决方案,在任何屏幕尺寸的UI上都显示UIView到我的PreviewView中。

Does anyone know how to map these to the frame of an on-screen UIView based upon the size of a previewView? 有谁知道如何根据PreviewView的大小将这些映射到屏幕上UIView的框架?

You should be able to take the size of the capture area, let's call that "captureSize" and then do this: 您应该能够获取捕获区域的大小,将其称为“ captureSize”,然后执行以下操作:

CGRect viewRect;
viewRect.origin.x = bounds.origin.x * captureSize.width;
viewRect.origin.y = bounds.origin.y * captureSize.height;
viewRect.size.width = bounds.size.width * captureSize.width;
viewRect.size.height = bounds.size.height * captureSize.height;

Now, this all depends how your previewView is setup and whether or not it has any content scaling, etc, but should give you a sense of the conversion. 现在,这一切都取决于您的PreviewView的设置方式以及它是否具有任何内容缩放等功能,但是应该使您对转换有所了解。

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

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