Skip to content

Commit

Permalink
“animation”
Browse files Browse the repository at this point in the history
  • Loading branch information
dupengw3 committed Aug 3, 2020
1 parent 4438bb8 commit d6cf8a9
Show file tree
Hide file tree
Showing 24 changed files with 427 additions and 87 deletions.
27 changes: 24 additions & 3 deletions ios/Classes/BarcodeScannerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,26 @@
import Foundation
import MTBBarcodeScanner

//let bundle = Bundle(for: BarcodeScannerViewController.self)
//
//let screenWidth = UIScreen.main.bounds.width
//
//let screenHeight = UIScreen.main.bounds.height
//
//let statusHeight = UIApplication.shared.statusBarFrame.height
//
//
//public func imageNamed(_ name:String)-> UIImage{
//
// guard let image = UIImage(named: name, in: bundle, compatibleWith: nil) else{
// return UIImage()
// }
//
// return image
//
//}


class BarcodeScannerViewController: UIViewController {
private var previewView: UIView?
private var scanRect: ScannerOverlay?
Expand Down Expand Up @@ -60,7 +80,7 @@ class BarcodeScannerViewController: UIViewController {
btn.titleLabel?.textColor = .white
btn.backgroundColor = UIColor.init(white: 0, alpha: 0.5)
btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
btn.setImage(UIImage.init(named: "hand_input") ?? UIImage(), for: .normal)
btn.setImage(imageNamed("hand_input"), for: .normal)
btn.addTarget(self, action: #selector(handInput), for: .touchUpInside)
return btn
}()
Expand All @@ -72,7 +92,7 @@ class BarcodeScannerViewController: UIViewController {
btn.backgroundColor = UIColor.init(white: 0, alpha: 0.5)
btn.titleLabel?.textColor = .white
btn.titleLabel?.font = UIFont.systemFont(ofSize: 12)
btn.setImage(UIImage.init(named: "torch") ?? UIImage(), for: .normal)
btn.setImage(imageNamed("torch"), for: .normal)
btn.addTarget(self, action: #selector(onToggleFlash), for: .touchUpInside)
return btn
}()
Expand Down Expand Up @@ -111,7 +131,7 @@ class BarcodeScannerViewController: UIViewController {
let btn = UIButton.init(frame: CGRect.init(x: 0, y: 0, width:type == 0 ? 150 : 90, height: 44))
btn.setTitle(type == 0 ?"添加/查询母开关" : "扫一扫", for: .normal)
btn.titleLabel?.textColor = .white
btn.setImage(UIImage.init(named: "backArrow") ?? UIImage(), for: .normal)
btn.setImage(imageNamed("backArrow"), for: .normal)
btn.addTarget(self, action: #selector(cancel), for: .touchUpInside)
navigationItem.leftBarButtonItem = UIBarButtonItem.init(customView: btn)
view.addSubview(torchBtn)
Expand Down Expand Up @@ -178,6 +198,7 @@ class BarcodeScannerViewController: UIViewController {
}
scanRect = ScannerOverlay(frame: bounds)
if let scanRect = scanRect {
scanRect.style = .grid
scanRect.translatesAutoresizingMaskIntoConstraints = false
scanRect.backgroundColor = UIColor.clear
view.addSubview(scanRect)
Expand Down
53 changes: 53 additions & 0 deletions ios/Classes/Common.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//
// Common.swift
// SwiftScanner
//
// Created by Jason on 2018/11/29.
// Copyright © 2018 Jason. All rights reserved.
//

import Foundation

let bundle = Bundle(for: BarcodeScannerViewController.self)

let screenWidth = UIScreen.main.bounds.width

let screenHeight = UIScreen.main.bounds.height

let statusHeight = UIApplication.shared.statusBarFrame.height


public func imageNamed(_ name:String)-> UIImage{
guard let image = UIImage(named: name, in: bundle, compatibleWith: nil) else{
return UIImage()
}
return image
}


extension UIImage{

/// 更改图片颜色
public func changeColor(_ color : UIColor) -> UIImage{

UIGraphicsBeginImageContextWithOptions(self.size, false, self.scale)

color.setFill()

let bounds = CGRect.init(x: 0, y: 0, width: self.size.width, height: self.size.height)

UIRectFill(bounds)

self.draw(in: bounds, blendMode: CGBlendMode.destinationIn, alpha: 1.0)

let tintedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()

guard let image = tintedImage else {
return UIImage()
}

return image
}

}
6 changes: 6 additions & 0 deletions ios/Classes/Media.xcassets/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"info" : {
"version" : 1,
"author" : "xcode"
}
}
22 changes: 22 additions & 0 deletions ios/Classes/Media.xcassets/ScanLine.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
22 changes: 22 additions & 0 deletions ios/Classes/Media.xcassets/ScanNet.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "2x"
},
{
"idiom" : "universal",
"filename" : "[email protected]",
"scale" : "3x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ios/Classes/Media.xcassets/backArrow.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Rectangle 19.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "backArrow-1.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Rectangle [email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ios/Classes/Media.xcassets/hand_input.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Mask.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
23 changes: 23 additions & 0 deletions ios/Classes/Media.xcassets/torch.imageset/Contents.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"filename" : "Mask.png",
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "[email protected]",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
Binary file added ios/Classes/Media.xcassets/torch.imageset/Mask.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
82 changes: 82 additions & 0 deletions ios/Classes/ScanAnimation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
//
// ScanAnimation.swift
// SwiftScanner
//
// Created by Jason on 2018/12/3.
// Copyright © 2018 Jason. All rights reserved.
//

import Foundation

class ScanAnimation:NSObject{

static let shared:ScanAnimation = {

let instance = ScanAnimation()

return instance
}()

lazy var animationImageView = UIImageView()

var displayLink:CADisplayLink?

var tempFrame:CGRect?

var contentHeight:CGFloat?

func startWith(_ rect:CGRect, _ parentView:UIView, imageView:UIImageView) {

tempFrame = rect

imageView.frame = tempFrame ?? CGRect.zero

animationImageView = imageView

contentHeight = parentView.bounds.height

parentView.addSubview(imageView)

setupDisplayLink()

}


@objc func animation() {

if animationImageView.frame.maxY > contentHeight! + 20 {
animationImageView.frame = tempFrame ?? CGRect.zero
}

animationImageView.transform = CGAffineTransform(translationX: 0, y: 2).concatenating(animationImageView.transform)

}


func setupDisplayLink() {

displayLink = CADisplayLink(target: self, selector: #selector(animation))

displayLink?.add(to: .current, forMode: .common)

displayLink?.isPaused = true

}


func startAnimation() {

displayLink?.isPaused = false

}


func stopAnimation() {

displayLink?.invalidate()

displayLink = nil

}

}
Loading

0 comments on commit d6cf8a9

Please sign in to comment.