我想使用带有扫描指示器的条形码阅读器。谁能告诉我应该使用哪个条形码 sdk。目前我正在使用 zbar sdk。在 zbar 中我们没有扫描指示器。请看我要实现的屏幕截图
最佳答案
我做了一个增强版的 @rgkobashi 答案,试图创建正方形并在正方形内为指示线设置动画。
扫描指示器和动画代码如下:
func createScanningIndicator() {
let height: CGFloat = 15
let opacity: Float = 0.4
let topColor = UIColor.green.withAlphaComponent(0)
let bottomColor = UIColor.green
let layer = CAGradientLayer()
layer.colors = [topColor.cgColor, bottomColor.cgColor]
layer.opacity = opacity
let squareWidth = view.frame.width * 0.6
let xOffset = view.frame.width * 0.2
let yOffset = view.frame.midY - (squareWidth / 2)
layer.frame = CGRect(x: xOffset, y: yOffset, width: squareWidth, height: height)
self.view.layer.insertSublayer(layer, at: 0)
let initialYPosition = layer.position.y
let finalYPosition = initialYPosition + squareWidth - height
let duration: CFTimeInterval = 2
let animation = CABasicAnimation(keyPath: "position.y")
animation.fromValue = initialYPosition as NSNumber
animation.toValue = finalYPosition as NSNumber
animation.duration = duration
animation.repeatCount = .infinity
animation.isRemovedOnCompletion = false
layer.add(animation, forKey: nil)
}
扫描正方形如下图:
func createScanningFrame() {
let lineLength: CGFloat = 15
let squareWidth = view.frame.width * 0.6
let topLeftPosX = view.frame.width * 0.2
let topLeftPosY = view.frame.midY - (squareWidth / 2)
let btmLeftPosY = view.frame.midY + (squareWidth / 2)
let btmRightPosX = view.frame.midX + (squareWidth / 2)
let topRightPosX = view.frame.width * 0.8
let path = UIBezierPath()
//top left
path.move(to: CGPoint(x: topLeftPosX, y: topLeftPosY + lineLength))
path.addLine(to: CGPoint(x: topLeftPosX, y: topLeftPosY))
path.addLine(to: CGPoint(x: topLeftPosX + lineLength, y: topLeftPosY))
//bottom left
path.move(to: CGPoint(x: topLeftPosX, y: btmLeftPosY - lineLength))
path.addLine(to: CGPoint(x: topLeftPosX, y: btmLeftPosY))
path.addLine(to: CGPoint(x: topLeftPosX + lineLength, y: btmLeftPosY))
//bottom right
path.move(to: CGPoint(x: btmRightPosX - lineLength, y: btmLeftPosY))
path.addLine(to: CGPoint(x: btmRightPosX, y: btmLeftPosY))
path.addLine(to: CGPoint(x: btmRightPosX, y: btmLeftPosY - lineLength))
//top right
path.move(to: CGPoint(x: topRightPosX, y: topLeftPosY + lineLength))
path.addLine(to: CGPoint(x: topRightPosX, y: topLeftPosY))
path.addLine(to: CGPoint(x: topRightPosX - lineLength, y: topLeftPosY))
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.strokeColor = UIColor.white.cgColor
shape.lineWidth = 3
shape.fillColor = UIColor.clear.cgColor
self.view.layer.insertSublayer(shape, at: 0)
}
关于ios - 带扫描指示器的条形码阅读器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28939085/
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
我在Rails应用程序中使用CarrierWave/Fog将视频上传到AmazonS3。有没有办法判断上传的进度,让我可以显示上传进度如何? 最佳答案 CarrierWave和Fog本身没有这种功能;你需要一个前端uploader来显示进度。当我不得不解决这个问题时,我使用了jQueryfileupload因为我的堆栈中已经有jQuery。甚至还有apostonCarrierWaveintegration因此您只需按照那里的说明操作即可获得适用于您的应用的进度条。 关于ruby-on-r
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
电脑启动出现显示器黑屏是一个相当常见的问题。如果您遇到了这个问题,不要惊慌,因为它有很多可能的原因,可以采取一些简单的措施来解决它。在本文中,小编将介绍下面4种常见的电脑启动后显示器黑屏的原因,排查这些原因,快速解决! 演示机型:联想Ideapad700-15ISK-ISE系统版本:Windows10一、显示器问题如果出现电脑启动后显示器黑屏的情况。那么首先您需要检查一下显示器是否正常工作。您可以通过更换另一个显示器或将当前显示器连接到另一台计算机来检查显示器是否存在问题。如果问题仍然存在,那么您可以排除显示器故障的可能性。 二、显卡问题如果您的电脑配备了独立显卡,那么显卡故障也可能是导致电脑
我想扫描未知数量的行,直到扫描完所有行。我如何在ruby中做到这一点?例如:putreturnsbetweenparagraphsforlinebreakadd2spacesatend_italic_or**bold**输入不是来自"file",而是通过STDIN。 最佳答案 在ruby中有很多方法可以做到这一点。大多数情况下,您希望一次处理一行,例如,您可以使用whileline=getsend或STDIN.each_linedo|line|end或者通过使用-n开关运行ruby,例如,这意味着上述循环之一(在每次迭代中将
当我将IO::popen与不存在的命令一起使用时,我在屏幕上打印了一条错误消息:irb>IO.popen"fakefake"#=>#irb>(irb):1:commandnotfound:fakefake有什么方法可以捕获此错误,以便我可以在脚本中进行检查? 最佳答案 是:升级到ruby1.9。如果您在1.9中运行它,则会引发Errno::ENOENT,您将能够拯救它。(编辑)这是在1.8中的一种hackish方式:error=IO.pipe$stderr.reopenerror[1]pipe=IO.popen'qwe'#
当我尝试使用“套接字”库中的方法“read_nonblock”时出现以下错误IO::EAGAINWaitReadable:Resourcetemporarilyunavailable-readwouldblock但是当我通过终端上的IRB尝试时它工作正常如何让它读取缓冲区? 最佳答案 IgetthefollowingerrorwhenItrytousethemethod"read_nonblock"fromthe"socket"library当缓冲区中的数据未准备好时,这是预期的行为。由于异常IO::EAGAINWaitReadab
我需要将目录中的一堆文件上传到S3。由于上传所需的90%以上的时间都花在了等待http请求完成上,所以我想以某种方式同时执行其中的几个。Fibers能帮我解决这个问题吗?它们被描述为解决此类问题的一种方法,但我想不出在http调用阻塞时我可以做任何工作的任何方法。有什么方法可以在没有线程的情况下解决这个问题? 最佳答案 我没有使用1.9中的纤程,但是1.8.6中的常规线程可以解决这个问题。尝试使用队列http://ruby-doc.org/stdlib/libdoc/thread/rdoc/classes/Queue.html查看文