SBTReadLoadingVCtr.swift 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. //
  2. // SBTReadLoadingVCtr.swift
  3. // SolarBT
  4. //
  5. // Created by weclouds on 2019/5/11.
  6. // Copyright © 2019 weclouds. All rights reserved.
  7. //
  8. import UIKit
  9. import SwiftPopup
  10. extension UIViewController {
  11. func swiftClassFromString(className: String) -> UIViewController! {
  12. // get the project name
  13. if let appName: String = Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as! String? {
  14. // 过滤无效字符 空格不转换的话 得不到准确类名
  15. let formattedAppName = appName.replacingOccurrences(of: " ", with: "_")
  16. //拼接控制器名
  17. let classStringName = "\(formattedAppName).\(className)"
  18. //将控制名转换为类
  19. let classType = NSClassFromString(classStringName) as? UIViewController.Type
  20. if let type = classType {
  21. let newVC = type.init()
  22. return newVC
  23. }
  24. }
  25. return nil;
  26. }
  27. }
  28. extension UIImageView {
  29. // 360度旋转图片
  30. func rotate360Degree() {
  31. log.debug("rotate360Degree --- ")
  32. let rotationAnimation = CABasicAnimation(keyPath: "transform.rotation.z") // 让其在z轴旋转
  33. rotationAnimation.fromValue = NSNumber(value: 0) //左幅度
  34. rotationAnimation.toValue = NSNumber(value: .pi * 2.0) // 旋转角度
  35. rotationAnimation.duration = 1.2 // 旋转周期
  36. rotationAnimation.isCumulative = true // 旋转累加角度
  37. rotationAnimation.repeatCount = HUGE // 旋转次数
  38. layer.add(rotationAnimation, forKey: "rotationAnimation")
  39. }
  40. // 停止旋转
  41. func stopRotate() {
  42. layer.removeAllAnimations()
  43. }
  44. }
  45. class SBTReadLoadingVCtr: SwiftPopup {
  46. var message :String?{
  47. didSet{
  48. }
  49. }
  50. var deviceName: String?
  51. @IBOutlet weak var deviceNameLabel: UILabel!
  52. @IBOutlet weak var messageLabel: UILabel!
  53. @IBOutlet weak var loadingImageV: UIImageView!
  54. @IBOutlet weak var backBtn: UIButton!
  55. @IBOutlet weak var box: UIView!
  56. override func viewDidLoad() {
  57. super.viewDidLoad()
  58. box.layer.masksToBounds = true
  59. box.layer.cornerRadius = 5
  60. self.messageLabel.text = self.message
  61. self.deviceNameLabel.text = self.deviceName
  62. backBtn.setTitle("Back".da_localizedStr(), for: .normal)
  63. }
  64. override func viewWillAppear(_ animated: Bool) {
  65. super.viewWillAppear(animated)
  66. loadingImageV.rotate360Degree()
  67. }
  68. override func viewDidAppear(_ animated: Bool) {
  69. super.viewDidAppear(animated)
  70. }
  71. open func dismiss(_ delay : TimeInterval) {
  72. self.perform(#selector(close), with: nil, afterDelay: delay)
  73. }
  74. @objc func close() {
  75. self.dismiss()
  76. // loadingImageV.stopRotate()
  77. }
  78. }