582f536d
yangbin
common:2022.1.28
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
//
// LBXScanNetAnimation.swift
// swiftScan
//
// Created by lbxia on 15/12/9.
// Copyright © 2015年 xialibing. All rights reserved.
//
import UIKit
class LBXScanNetAnimation: UIImageView {
var isAnimationing = false
var animationRect = CGRect.zero
public static func instance() -> LBXScanNetAnimation {
return LBXScanNetAnimation()
}
func startAnimatingWithRect(animationRect: CGRect, parentView: UIView, image: UIImage?) {
self.image = image
self.animationRect = animationRect
parentView.addSubview(self)
isHidden = false
isAnimationing = true
if image != nil {
stepAnimation()
}
}
@objc func stepAnimation() {
guard isAnimationing else {
return
}
var frame = animationRect
let hImg = image!.size.height * animationRect.size.width / image!.size.width
frame.origin.y -= hImg
frame.size.height = hImg
self.frame = frame
alpha = 0.0
UIView.animate(withDuration: 1.2, animations: {
self.alpha = 1.0
var frame = self.animationRect
let hImg = self.image!.size.height * self.animationRect.size.width / self.image!.size.width
frame.origin.y += (frame.size.height - hImg)
frame.size.height = hImg
self.frame = frame
}, completion: { _ in
self.perform(#selector(LBXScanNetAnimation.stepAnimation), with: nil, afterDelay: 0.3)
})
}
func stopStepAnimating() {
isHidden = true
isAnimationing = false
}
}
|