我试图通过点击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
})
})
}
答案 0 :(得分:0)
更改最后一行,它应该工作
@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 })
})
}