gpt4 book ai didi

swift - 无法将类型 '(String) -> Void' 的值转换为预期参数类型 '((AnyObject!) -> Void)!'

转载 作者:行者123 更新时间:2023-11-30 13:13:56 26 4
gpt4 key购买 nike

我正在尝试通过点击 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com