我正在尝试使用 iOS 7 的最新条形码 api 在检测到的条形码上绘制一个红色矩形。我已经设法拉入边界和角落,但我不太知道如何获取这些信息并将其应用到我的视图中。
在 viewDidLoad 方法中,我定义了一旦找到我将用来覆盖条形码的视图:
//Initialize Laser View
laserView = [[UIView alloc] init];
laserView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleBottomMargin;
laserView.layer.borderColor = [UIColor redColor].CGColor;
laserView.layer.borderWidth = 2;
[self.view addSubview:laserView];
在 didOutputMetadataObjects 中,我准备了激光视图并拉入条形码边界和角落:
//Prepare Laser View's frame
CGRect laser = CGRectZero;
laser = barcodeObject.bounds;
NSLog(@"Bounds: %@", NSStringFromCGRect(barcodeObject.bounds));
NSLog(@"Frame: %@", barcodeObject.corners);
//Update Laser
laserView.frame = laser;
在我最近的一次跑步中,我得到了界限:{{7.0565414, 314.25}, {265.26062, 1.499999}}
和角落我得到了:
(
{
X = "7.056541";
Y = "314.25";
},
{
X = "7.056541";
Y = "315.75";
},
{
X = "272.3172";
Y = "315.75";
},
{
X = "272.3172";
Y = "314.25";
}
)
我希望能够将 cgrect 紧紧地包裹在条形码周围。这是我正在尝试做的一个例子: