FloatingWindow.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. //
  2. // FloatingWindow.m
  3. // AIIM
  4. //
  5. // Created by gan on 2025/7/9.
  6. //
  7. #import <Foundation/Foundation.h>
  8. #import "FloatingWindow.h"
  9. #import "APPLockView.h"
  10. #import "FloatJSWindow.h"
  11. #import "AppDelegate.h"
  12. @interface FloatingWindow ()
  13. @property (nonatomic, strong) APPLockView *lockView;
  14. @property (nonatomic, strong) UIView *JSWindow;
  15. @property (nonatomic, assign) CGRect innitframe;
  16. @property (nonatomic, strong) UIButton *floadBT;
  17. @property (nonatomic, strong) UIView *floadNotView;
  18. @end
  19. @implementation FloatingWindow
  20. - (instancetype)initWithFrame:(CGRect)frame {
  21. self = [super initWithFrame:frame];
  22. if (self) {
  23. _innitframe = frame;
  24. self.windowLevel = UIWindowLevelAlert + 1;
  25. self.backgroundColor = [UIColor clearColor];
  26. self.rootViewController = [UIViewController new];
  27. }
  28. return self;
  29. }
  30. - (void)show:(NSInteger)type{
  31. self.hidden = NO;
  32. [self makeKeyAndVisible];
  33. if(type==1){
  34. [self initlockView];
  35. }
  36. }
  37. - (void)hide {
  38. self.hidden = YES;
  39. }
  40. -(void)initlockView{
  41. if(_JSWindow){
  42. _JSWindow.hidden=YES;
  43. }
  44. if(_lockView){
  45. _lockView.hidden=NO;
  46. return;
  47. }
  48. else{
  49. weakSelf(self);
  50. _lockView=[[APPLockView alloc] initWithFrame:self.frame];
  51. _lockView.onShide = ^{
  52. [weakself hide];
  53. };
  54. [self addSubview:_lockView];
  55. }
  56. }
  57. - (void)showView:(UIView *)view{
  58. self.hidden = NO;
  59. if(_lockView){
  60. _lockView.hidden=YES;
  61. }
  62. if(_JSWindow){
  63. _JSWindow.hidden=NO;
  64. NSLog(@"_JSWindow.hidden=NO");
  65. return;
  66. }
  67. else{
  68. _JSWindow=view;
  69. NSLog(@"__JSWindow=view");
  70. [self addSubview:_JSWindow];
  71. }
  72. }
  73. -(void)viewInFload:(NSInteger)type{
  74. if(type==0){
  75. self.frame=_innitframe;
  76. _floadNotView.hidden = YES;
  77. if(_JSWindow){
  78. _JSWindow.hidden=NO;
  79. }
  80. }
  81. else if(type==1 || type==2){
  82. if(_JSWindow){
  83. _JSWindow.hidden=YES;
  84. }
  85. if(_lockView){
  86. _lockView.hidden=YES;
  87. }
  88. [self initfloadNotView:type];
  89. self.frame =CGRectMake(100, 180, 70, 70);
  90. }
  91. }
  92. -(void)floadBTsel{
  93. NSLog(@"floadBTsel----------");
  94. [self viewInFload:0];
  95. UIWindow *keyWindow = [UIApplication sharedApplication].delegate.window;
  96. [keyWindow endEditing:YES];
  97. }
  98. -(void)initfloadNotView:(NSInteger)type{
  99. NSString *icon = @"Cyuyinth";
  100. if (type==2) {
  101. icon = @"Cshipinth";
  102. }
  103. if(_floadNotView){
  104. [_floadBT setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
  105. _floadNotView.hidden=NO;
  106. return;
  107. }
  108. else{
  109. _floadNotView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 70, 70)];
  110. _floadNotView.backgroundColor = globalColor(GCTypeOrangeR);
  111. _floadNotView.layer.cornerRadius = 8.0f;
  112. [self addSubview:_floadNotView];
  113. _floadBT = [UIButton buttonWithType:UIButtonTypeCustom];
  114. [_floadBT setImage:[UIImage imageNamed:icon] forState:UIControlStateNormal];
  115. [_floadNotView addSubview:_floadBT];
  116. [_floadBT addTarget:self action:@selector(floadBTsel) forControlEvents:UIControlEventTouchUpInside];
  117. [_floadBT mas_makeConstraints:^(MASConstraintMaker *make) {
  118. make.size.mas_equalTo(CGSizeMake(50, 50));
  119. make.top.mas_equalTo(10);
  120. make.left.mas_equalTo(10);
  121. }];
  122. }
  123. }
  124. @end