补充部分(扫描界面):
扫面界面的组成部分一般有扫描区域部分,蒙版涂层部分,以及扫面动画部分组成
/*扫描动画部分*/
import UIKit
private let MarginTop:CGFloat = 10
class ScanAnimationView: UIView {
var lineImage:UIImageView!
var timer:Timer!
var addCut:Int!
/*初始化方法*/
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = UIColor.clear
self.lineImage = UIImageView.init(image: UIImage(named: "homeScanLine"))
self.addSubview(self.lineImage)
lineImage.frame = CGRect(x: 0, y: MarginTop, width: self.bounds.size.width, height: 10)
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
}
override func draw(_ rect: CGRect) {
self.drawScanView(rect)
}
/*绘制四个小角度*/
func drawScanView(_ rect:CGRect) -> Void {
let width:CGFloat = self.frame.size.width
let height:CGFloat = self.frame.size.height
let lineHeight:CGFloat = width / 15
let lineWidth:CGFloat = width / 15
let ctx:CGContext! = UIGraphicsGetCurrentContext();
ctx.setStrokeColor(UIColor.green.cgColor)
ctx.setLineWidth(3.5)
/*左上角*/
let leftTopPath:CGMutablePath = CGMutablePath.init()
leftTopPath.move(to: CGPoint(x: 0, y: lineHeight))
leftTopPath.addLine(to: CGPoint(x: 0, y: 0))
leftTopPath.addLine(to: CGPoint(x: lineWidth, y: 0))
ctx.addPath(leftTopPath)
ctx.strokePath()
/*右上角*/
let