TiUIManager.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. //
  2. // TiUIMangagerNew.m
  3. // TiSDKDemo
  4. //
  5. // Created by iMacA1002 on 2019/12/2.
  6. // Copyright © 2020 Tillusory Tech. All rights reserved.
  7. //
  8. #import "TiUIManager.h"
  9. #import "TIConfig.h"
  10. #import "TiUIMainMenuView.h"
  11. @interface TiUIManager ()
  12. @property(nonatomic, weak) id <TiUIManagerDelegate> delegate;
  13. //主窗口
  14. @property(nonatomic, strong) UIWindow *superWindow;
  15. //添加退出手势的View
  16. @property(nonatomic, strong) UIView *exitTapView;
  17. //美颜模块主要功能UI
  18. @property(nonatomic, strong) TiUIMainMenuView *tiUIViewBoxView;
  19. @end
  20. static TiUIManager *shareManager = NULL;
  21. static dispatch_once_t token;
  22. @implementation TiUIManager
  23. // MARK: --单例初始化方法--
  24. + (TiUIManager *)shareManager {
  25. dispatch_once(&token, ^{
  26. shareManager = [[TiUIManager alloc] init];
  27. });
  28. return shareManager;
  29. }
  30. +(void)releaseShareManager{
  31. token = 0; // 只有置成0,GCD才会认为它从未执行过.它默认为0.这样才能保证下次再次调用shareInstance的时候,再次创建对象.
  32. // [shareManager release];
  33. shareManager = nil;
  34. }
  35. -(instancetype)init{
  36. if ([super init]) {
  37. self.showsDefaultUI = NO;
  38. }
  39. return self;
  40. }
  41. // MARK: --懒加载--
  42. -(UIWindow *)superWindow{
  43. if (_superWindow==nil) {
  44. _superWindow = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  45. _superWindow.windowLevel = UIWindowLevelAlert;
  46. _superWindow.userInteractionEnabled = YES;
  47. [_superWindow makeKeyAndVisible];
  48. _superWindow.hidden = YES;//初始隐藏
  49. }
  50. return _superWindow;
  51. }
  52. -(TiUIDefaultButtonView *)defaultButton{
  53. if (!self.showsDefaultUI) {
  54. [_defaultButton removeFromSuperview];
  55. _defaultButton =nil;
  56. return _defaultButton;
  57. }
  58. if (_defaultButton==nil) {
  59. _defaultButton = [[TiUIDefaultButtonView alloc]initWithFrame:CGRectMake(0, SCREEN_HEIGHT - TiUIViewBoxTotalHeight, SCREEN_WIDTH, TiUIViewBoxTotalHeight)];
  60. WeakSelf;
  61. [_defaultButton setOnClickBlock:^(NSInteger tag) {
  62. switch (tag) {
  63. case 0:
  64. //显示美颜UI
  65. [weakSelf showMainMenuView];
  66. break;
  67. case 1:
  68. //拍照
  69. [weakSelf.delegate didClickCameraCaptureButton];
  70. break;
  71. case 2:
  72. //切换摄像头
  73. [weakSelf.delegate didClickSwitchCameraButton];
  74. break;
  75. default:
  76. break;
  77. }
  78. }];
  79. }
  80. return _defaultButton;
  81. }
  82. -(UIView *)exitTapView{
  83. if (_exitTapView ==nil) {
  84. _exitTapView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - TiUIViewBoxTotalHeight)];
  85. _exitTapView.hidden = YES;
  86. _exitTapView.userInteractionEnabled = YES;
  87. [_exitTapView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onExitTap:)]];
  88. }
  89. return _exitTapView;
  90. }
  91. -(TiUIMainMenuView *)tiUIViewBoxView{
  92. if (_tiUIViewBoxView==nil) {
  93. // 展示高度 SCREEN_HEIGHT - TiUIViewBoxTotalHeight
  94. // 隐藏高度 SCREEN_HEIGHT
  95. _tiUIViewBoxView = [[TiUIMainMenuView alloc]initWithFrame:CGRectMake(0,SCREEN_HEIGHT, SCREEN_WIDTH, TiUIViewBoxTotalHeight)];
  96. }
  97. return _tiUIViewBoxView;
  98. }
  99. // MARK: --弹出美颜UI相关--
  100. -(void)showMainMenuView{
  101. [self hiddenAllViews:NO];
  102. [UIView animateWithDuration:0.3 animations:^{
  103. self.tiUIViewBoxView.frame = CGRectMake(0,SCREEN_HEIGHT- TiUIViewBoxTotalHeight, SCREEN_WIDTH , TiUIViewBoxTotalHeight);
  104. }];
  105. }
  106. // MARK: --退出手势相关--
  107. - (void)onExitTap:(UITapGestureRecognizer *)recognizer {
  108. if ([self.delegate respondsToSelector:@selector(didClickOnExitTap)]) {
  109. [self.delegate didClickOnExitTap];
  110. }
  111. [self popAllViews];
  112. }
  113. - (void)popAllViews {
  114. [UIView animateWithDuration:0.1 animations:^{
  115. self.tiUIViewBoxView.frame = CGRectMake(0,SCREEN_HEIGHT, SCREEN_WIDTH, TiUIViewBoxTotalHeight);
  116. } completion:^(BOOL finished) {
  117. [self hiddenAllViews:YES];
  118. }];
  119. }
  120. -(void)hiddenAllViews:(BOOL)YESNO{
  121. self.tiUIViewBoxView.hidden = YESNO;
  122. self.exitTapView.hidden = YESNO;
  123. if (_defaultButton) {
  124. _defaultButton.hidden = !YESNO;
  125. }
  126. if (_superWindow) {
  127. _superWindow.hidden = YESNO;
  128. }
  129. }
  130. // MARK: --loadToWindow 相关代码--
  131. - (void)loadToWindowDelegate:(id<TiUIManagerDelegate>)delegate{
  132. self.delegate = delegate;
  133. // if (self.showsDefaultUI) {
  134. // [self.superWindow addSubview:self.defaultButton];
  135. // }
  136. [self.superWindow addSubview:self.exitTapView];
  137. [self.superWindow addSubview:self.tiUIViewBoxView];
  138. }
  139. - (void)loadToView:(UIView* )view forDelegate:(id<TiUIManagerDelegate>)delegate{
  140. self.delegate = delegate;
  141. if (self.showsDefaultUI) {
  142. [view addSubview:self.defaultButton];
  143. }
  144. [view addSubview:self.exitTapView];
  145. [view addSubview:self.tiUIViewBoxView];
  146. }
  147. - (UIView*)returnLoadToViewDelegate:(id<TiUIManagerDelegate>)delegate{
  148. self.delegate = delegate;
  149. UIView *view = [UIView new];
  150. view.frame = [UIScreen mainScreen].bounds;
  151. if (self.showsDefaultUI) {
  152. [view addSubview:self.defaultButton];
  153. }
  154. [view addSubview:self.exitTapView];
  155. [view addSubview:self.tiUIViewBoxView];
  156. return view;
  157. }
  158. // MARK: --destroy释放 相关代码--
  159. - (void)destroy{
  160. // TODO: --此处代码属性获取应使用 _(下划线) --
  161. [_defaultButton removeFromSuperview];
  162. _defaultButton = nil;
  163. [_exitTapView removeFromSuperview];
  164. _exitTapView = nil;
  165. [_tiUIViewBoxView removeFromSuperview];
  166. _tiUIViewBoxView = nil;
  167. [_superWindow removeFromSuperview];
  168. _superWindow = nil;
  169. [TiUIManager releaseShareManager];
  170. }
  171. @end