- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 AVCaptureSession在 Swift 应用程序中扫描二维码。我想在检测到的 QR 码周围画一个框,但我在转换 AVMetadataMachineReadableCodeObject 的“角”属性时遇到问题变成可用的东西。
var corners: [AnyObject]! { get }
The value of this property is an array of CFDictionary objects, each of which has been created from a CGPoint struct using the CGPointCreateDictionaryRepresentation function, representing the coordinates of the corners of the object with respect to the image in which it resides.
我试过这个(基于 project by werner77 )但我得到以下编译器错误 “'CGPoint?'与‘CGPoint’不同”
// MARK: - AVCaptureMetadataOutputObjectsDelegate
func captureOutput(captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [AnyObject]!, fromConnection connection: AVCaptureConnection!) {
let metadataObject = metadataObjects[0] as AVMetadataMachineReadableCodeObject;
var corners = metadataObject.corners as Array<NSDictionary>;
var topLeftDict = corners[0] as NSDictionary;
var topLeft : CGPoint?
// COMPILE ERROR: 'CGPoint?' is not identical to 'CGPoint'
CGPointMakeWithDictionaryRepresentation(topLeftDict, &topLeft)
}
如有任何帮助,我们将不胜感激。
最佳答案
了解可选项。
任何类型都可以附加?
,这意味着它也可以是nil
。这样做的好处是,您必须显式地处理或忽略 nil 对象,这与 Objective-C 不同,在 Objective-C 中,nil 对象可能会导致无法追踪的错误。
当从字典中获取对象时,它必须是可选的,因为字典中可能不存在该键。 CGPointMakeWithDictionaryRepresentation
需要一个非可选值,因此您必须使用初始化的非可选值。
// Playground:
var point = CGPointMake(1, 2)
var dictionary = CGPointCreateDictionaryRepresentation(point)
var aPoint = CGPointZero
CGPointMakeWithDictionaryRepresentation(dictionary, &aPoint)
aPoint // x 1, y 2
关于ios - Swift 中的 CGPointMakeWithDictionaryRepresentation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26124371/
我正在使用 AVCaptureSession在 Swift 应用程序中扫描二维码。我想在检测到的 QR 码周围画一个框,但我在转换 AVMetadataMachineReadableCodeObjec
我是一名优秀的程序员,十分优秀!