我正在尝试通过点击 captureDoc 按钮来捕获图像。但是当我编写这个函数时,我突然在完成处理程序中收到上述错误,
self.scanDoc.captureImageWithCompletionHander({(imageFilePath: String) -> Void in
我不明白出了什么问题。 下面是我的 captureDoc 函数的代码。
@IBAction func captureDoc(sender: AnyObject) {
weak var weakSelf = self
self.scanDoc.captureImageWithCompletionHander({(imageFilePath: String) -> Void in
var captureImageView: UIImageView = UIImageView(image: UIImage.imageWithContentsOfFile(imageFilePath)!)
captureImageView.backgroundColor = UIColor(white: 0.0, alpha: 0.7)
captureImageView.frame = CGRectOffset(weakSelf.view.bounds, 0, -weakSelf.view.bounds.size.height)
captureImageView.alpha = 1.0
captureImageView.contentMode = .ScaleAspectFit
captureImageView.userInteractionEnabled = true
weakSelf.view!.addSubview(captureImageView)
var dismissTap: UITapGestureRecognizer = UITapGestureRecognizer(target: weakSelf, action: #selector(self.dismissPreview))
captureImageView.addGestureRecognizer(dismissTap)
UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.7, options: .AllowUserInteraction, animations: {() -> Void in
captureImageView.frame = weakSelf.view.bounds
})
})
}
最佳答案
更改最后一行,它应该可以工作
@IBAction func captureDoc(_ sender: UIButton) {
weak var weakSelf = self
self.scanDoc.captureImageWithCompletionHander({(imageFilePath: String?) -> Void in
var captureImageView: UIImageView = UIImageView(image: UIImage.imageWithContentsOfFile(imageFilePath!)!)
captureImageView.backgroundColor = UIColor(white: 0.0, alpha: 0.7)
captureImageView.frame = CGRectOffset(weakSelf.view.bounds, 0, -weakSelf.view.bounds.size.height)
captureImageView.alpha = 1.0
captureImageView.contentMode = .ScaleAspectFit
captureImageView.userInteractionEnabled = true
weakSelf.view!.addSubview(captureImageView)
var dismissTap: UITapGestureRecognizer = UITapGestureRecognizer(target: weakSelf, action: #selector(self.dismissPreview))
captureImageView.addGestureRecognizer(dismissTap)
UIView.animateWithDuration(0.7, delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 0.7, options: .AllowUserInteraction, animations: {() -> Void in
captureImageView.frame = weakSelf.view.bounds
}, completion: { _ in })
})
}
关于swift - 无法将类型 '(String) -> Void' 的值转换为预期参数类型 '((AnyObject!) -> Void)!',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38429757/