O2AudioPlayFloatingWindow.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. //
  2. // O2AudioPlayFloatingWindow.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/7/28.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import UIKit
  9. import CocoaLumberjack
  10. class O2AudioPlayFloatingWindow: UIWindow {
  11. override init(frame: CGRect) {
  12. super.init(frame: frame)
  13. self.initView()
  14. }
  15. required init?(coder: NSCoder) {
  16. fatalError("init(coder:) has not been implemented")
  17. }
  18. private var stopBtn: UIButton!
  19. private func initView() {
  20. DDLogDebug("初始化悬浮按钮。。。。")
  21. self.backgroundColor = .clear
  22. self.windowLevel = UIWindow.Level.alert + 1
  23. self.rootViewController = UIViewController()
  24. self.makeKeyAndVisible()
  25. stopBtn = UIButton.init(type: .custom)
  26. stopBtn.frame = CGRect(x: 0, y: 0, width: 60, height: 60)
  27. stopBtn.setImage(UIImage(named: "icon_play_off"), for: .normal)
  28. self.addSubview(stopBtn)
  29. stopBtn.addTapGesture { (tap) in
  30. DDLogDebug("点击关闭")
  31. self.stopPlay()
  32. }
  33. }
  34. /// 关闭音频播放
  35. func stopPlay() {
  36. AudioPlayerManager.shared.stopAudio()
  37. self.hideFloatingBtn()
  38. }
  39. func showFloatingBtn() {
  40. self.isHidden = false
  41. }
  42. func hideFloatingBtn() {
  43. self.isHidden = true
  44. }
  45. }