无法转换类型'(字符串)的值 - >虚空'预期的参数类型'((AnyObject!) - > Void)!'

时间:2016-07-18 06:20:25

标签: swift uiimageview completionhandler anyobject

我试图通过点击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
                })

            })

}

1 个答案:

答案 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 })

        })

}