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. [[NSObject getKeyWindow] addSubview:self.dragWindow];
  28. // if (@available(iOS 13.0, *)) {
  29. // NSSet* windowScene = [UIApplication sharedApplication].connectedScenes;
  30. // self.dragWindow.windowScene = windowScene.anyObject;
  31. // }
  32. }
  33. - (void)dragAction:(DRAG_ACTION)action {
  34. switch (action) {
  35. case DRAG_ACTION_CANCEL:
  36. {
  37. [self resignDragWindow];
  38. // 静音所有的声音
  39. [[NSNotificationCenter defaultCenter] postNotificationName:@"muteLiveAudio" object:nil];
  40. }
  41. break;
  42. case DRAG_ACTION_CLICK: // 返回到指定页面
  43. {
  44. // 返回到对应的页面
  45. // 获取当前页面的层级
  46. [self resignDragWindow];
  47. // 回到登录界面
  48. [self.rootVC popToRootViewControllerAnimated:YES];
  49. }
  50. break;
  51. default:
  52. break;
  53. }
  54. }
  55. - (void)resignDragWindow {
  56. _hasShowWindow = NO;
  57. [self.dragWindow.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  58. // self.dragWindow.rootViewController = nil;
  59. // [self.dragWindow resignKeyWindow];
  60. [self.dragWindow removeFromSuperview];
  61. _dragWindow = nil;
  62. }
  63. @end