KSDragWindowManager.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. //
  2. // KSDragWindowManager.m
  3. // StudentDaya
  4. //
  5. // Created by 王智 on 2022/5/16.
  6. // Copyright © 2022 DayaMusic. All rights reserved.
  7. //
  8. #import "KSDragWindowManager.h"
  9. @implementation KSDragWindowManager
  10. + (instancetype)sharedManager {
  11. static KSDragWindowManager *manager;
  12. static dispatch_once_t onceToken;
  13. dispatch_once(&onceToken, ^{
  14. manager = [[KSDragWindowManager alloc] init];
  15. });
  16. return manager;
  17. }
  18. - (void)initDragWindow {
  19. _hasShowWindow = YES;
  20. CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
  21. CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
  22. self.dragWindow = [[KSDragWindow alloc] initWithFrame:CGRectMake(screenWidth - KSDragWindowWidth, screenHeight - KSDragWindowHeight - KSDragWindowHeightBottomSpace , KSDragWindowWidth, KSDragWindowHeight)];
  23. MJWeakSelf;
  24. [self.dragWindow clickAction:^(DRAG_ACTION action) {
  25. [weakSelf dragAction:action];
  26. }];
  27. if (@available(iOS 13.0, *)) {
  28. NSSet* windowScene = [UIApplication sharedApplication].connectedScenes;
  29. self.dragWindow.windowScene = windowScene.anyObject;
  30. }
  31. }
  32. - (void)dragAction:(DRAG_ACTION)action {
  33. switch (action) {
  34. case DRAG_ACTION_CANCEL:
  35. {
  36. [self resignDragWindow];
  37. // 静音所有的声音
  38. [[NSNotificationCenter defaultCenter] postNotificationName:@"muteLiveAudio" object:nil];
  39. }
  40. break;
  41. case DRAG_ACTION_CLICK: // 返回到指定页面
  42. {
  43. // 返回到对应的页面
  44. // 获取当前页面的层级
  45. [self resignDragWindow];
  46. // 回到登录界面
  47. [self.rootVC popToRootViewControllerAnimated:YES];
  48. }
  49. break;
  50. default:
  51. break;
  52. }
  53. }
  54. - (void)resignDragWindow {
  55. _hasShowWindow = NO;
  56. [self.dragWindow.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  57. self.dragWindow.rootViewController = nil;
  58. [self.dragWindow resignKeyWindow];
  59. [self.dragWindow removeFromSuperview];
  60. _dragWindow = nil;
  61. }
  62. @end