PublicView.m 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. //
  2. // PublicView.m
  3. // YBVideo
  4. //
  5. // Created by YunBao on 2018/6/29.
  6. // Copyright © 2018年 cat. All rights reserved.
  7. //
  8. #import "PublicView.h"
  9. @interface PublicView()<CAAnimationDelegate>
  10. @end
  11. @implementation PublicView
  12. /***************************** 指示器视图(start) **********************************/
  13. /***************************** 指示器 **********************************/
  14. #pragma mark - 指示器显示
  15. +(void)indictorShow {
  16. UIViewController *currentVC = [UIApplication sharedApplication].keyWindow.rootViewController;
  17. PublicView *pubV = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:0];
  18. pubV.frame = CGRectMake(0, statusbarHeight+64, _window_width, _window_height-statusbarHeight-64-ShowDiff);
  19. BOOL have = NO;
  20. for (UIView *view in currentVC.view.subviews) {
  21. if ([view isKindOfClass:[PublicView class]]) {
  22. have = YES;
  23. break;
  24. }
  25. }
  26. if (have==NO) {
  27. [currentVC.view addSubview:pubV];
  28. }
  29. pubV.hidden = NO;
  30. //开始旋转
  31. [pubV.indictorV startAnimating];
  32. }
  33. #pragma mark - 指示器消失
  34. +(void)indictorHide {
  35. UIViewController *currentVC = [UIApplication sharedApplication].keyWindow.rootViewController;
  36. for (UIView *view in currentVC.view.subviews) {
  37. if ([view isKindOfClass:[PublicView class]]) {
  38. PublicView *pubV = (PublicView *)view;
  39. [pubV.indictorV stopAnimating];
  40. [pubV.indictorV setHidesWhenStopped:YES];
  41. pubV.hidden = YES;
  42. }
  43. }
  44. }
  45. /***************************** 指示器视图(end) **********************************/
  46. #pragma mark =====================================================================
  47. /***************************** 数据图形视图(start) **********************************/
  48. /***************************** 无数据(带图) **********************************/
  49. +(void)publicHide:(UIView *)superView {
  50. if (!superView) {
  51. superView = [UIApplication sharedApplication].keyWindow;
  52. }
  53. for (UIView *subv in superView.subviews) {
  54. if ([subv isKindOfClass:[PublicView class]]) {
  55. [subv removeFromSuperview];
  56. }
  57. }
  58. }
  59. #pragma mark - 无数据提示
  60. +(void)hiddenImgNoData:(UIView *)superView {
  61. [self publicHide:superView];
  62. }
  63. +(void)showImgNoData:(UIView *)superView name:(NSString *)imgName text:(NSString *)text centerY:(CGFloat)centerY whRate:(CGFloat)wh{
  64. for (UIView *subv in superView.subviews) {
  65. if ([subv isKindOfClass:[PublicView class]]) {
  66. [subv removeFromSuperview];
  67. }
  68. }
  69. /**
  70. * 公用类尺寸谨慎修改
  71. */
  72. PublicView *_noData = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:1];
  73. _noData.frame = CGRectMake(0, 0, superView.width, superView.height);
  74. _noData.noDataIV.image = [UIImage imageNamed:imgName];
  75. _noData.noDataTextL.text = text;
  76. [superView addSubview:_noData];
  77. [_noData.noDataIV mas_makeConstraints:^(MASConstraintMaker *make) {
  78. make.height.equalTo(_noData.mas_width).multipliedBy(0.2);
  79. make.width.equalTo(_noData.noDataIV.mas_height).multipliedBy(wh);
  80. make.centerX.equalTo(_noData);
  81. make.centerY.equalTo(_noData.mas_centerY).multipliedBy(centerY);
  82. }];
  83. [_noData.noDataTextL mas_makeConstraints:^(MASConstraintMaker *make) {
  84. make.centerX.equalTo(_noData);
  85. make.width.lessThanOrEqualTo(_noData.mas_width).multipliedBy(0.8);
  86. make.top.equalTo(_noData.noDataIV.mas_bottom).offset(10);
  87. }];
  88. }
  89. /***************************** 无数据(文字) **********************************/
  90. +(void)showTextNoData:(UIView *)superView text1:(NSString *)str1 text2:(NSString *)str2 centerY:(CGFloat)cY{
  91. for (UIView *subv in superView.subviews) {
  92. if ([subv isKindOfClass:[PublicView class]]) {
  93. [subv removeFromSuperview];
  94. }
  95. }
  96. /**
  97. * 公用类尺寸谨慎修改
  98. */
  99. PublicView *_noData = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:2];
  100. _noData.frame = CGRectMake(0, 0, superView.width, superView.height);
  101. _noData.noDataText1.text = str1;
  102. _noData.noDataText2.text = str2;
  103. [superView addSubview:_noData];
  104. [_noData.noDataText1 mas_makeConstraints:^(MASConstraintMaker *make) {
  105. make.height.mas_equalTo(20);
  106. make.width.centerX.equalTo(_noData);
  107. make.centerY.equalTo(_noData.mas_centerY).multipliedBy(cY);
  108. }];
  109. [_noData.noDataText2 mas_makeConstraints:^(MASConstraintMaker *make) {
  110. make.centerX.width.height.equalTo(_noData.noDataText1);
  111. make.top.equalTo(_noData.noDataText1.mas_bottom).offset(10);
  112. }];
  113. }
  114. +(void)hiddenTextNoData:(UIView *)superView {
  115. [self publicHide:superView];
  116. }
  117. +(void)showImgNoData:(UIView *)superView name:(NSString *)imgName text:(NSString *)text{
  118. for (UIView *subv in superView.subviews) {
  119. if ([subv isKindOfClass:[PublicView class]]) {
  120. [subv removeFromSuperview];
  121. }
  122. }
  123. /**
  124. * 公用类尺寸谨慎修改
  125. */
  126. PublicView *_noData = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:1];
  127. _noData.frame = CGRectMake(0, 0, superView.width, superView.height);
  128. _noData.noDataIV.image = [UIImage imageNamed:imgName];
  129. _noData.noDataTextL.text = text;
  130. [superView addSubview:_noData];
  131. }
  132. /***************************** 评论加载中 **********************************/
  133. +(void)showCommenting:(UIView *)superView {
  134. for (UIView *subv in superView.subviews) {
  135. if ([subv isKindOfClass:[PublicView class]]) {
  136. [subv removeFromSuperview];
  137. }
  138. }
  139. PublicView *_comment = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:3];
  140. _comment.frame = CGRectMake(0, 0, superView.width, superView.height);
  141. [superView addSubview:_comment];
  142. }
  143. +(void)hideCommenting:(UIView *)superView {
  144. [self publicHide:superView];
  145. }
  146. /***************************** 个人中心动图 **********************************/
  147. +(void)showCenterGif:(UIView *)superView {
  148. if (!superView) {
  149. superView = [UIApplication sharedApplication].keyWindow;
  150. }
  151. for (UIView *subv in superView.subviews) {
  152. if ([subv isKindOfClass:[PublicView class]]) {
  153. [subv removeFromSuperview];
  154. }
  155. }
  156. PublicView *_comment = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:4];
  157. _comment.frame = CGRectMake(0, _window_height-100-49-ShowDiff, _window_width, 100);
  158. UIImage *gifImg = [UIImage imageNamed:getImagename(@"center_gif")];//[UIImage sd_animatedGIFNamed:@"center_gif"];
  159. [_comment.gifIV setImage:gifImg];
  160. //上下浮动
  161. CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:@"transform.translation.y"];
  162. CGFloat duration = 1.f;
  163. CGFloat height = 7.f;
  164. CGFloat currentY = _comment.gifIV.transform.ty;
  165. animation.duration = duration;
  166. animation.values = @[@(currentY),@(currentY - height/4),@(currentY - height/4*2),@(currentY - height/4*3),@(currentY - height),@(currentY - height/ 4*3),@(currentY - height/4*2),@(currentY - height/4),@(currentY)];
  167. animation.keyTimes = @[ @(0), @(0.025), @(0.085), @(0.2), @(0.5), @(0.8), @(0.915), @(0.975), @(1) ];
  168. animation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
  169. animation.repeatCount = HUGE_VALF;
  170. [_comment.gifIV.layer addAnimation:animation forKey:nil];
  171. [superView addSubview:_comment];
  172. }
  173. +(void)hideCenterGif:(UIView *)superView {
  174. [self publicHide:superView];
  175. }
  176. /***************************** 数据图形视图(end) **********************************/
  177. #pragma mark 倒计时start
  178. +(instancetype)showTimerView:(PubliccViewBlock)complete {
  179. PublicView *pView = [[[NSBundle mainBundle]loadNibNamed:@"PublicView" owner:nil options:nil]objectAtIndex:5];
  180. [pView setUpView];
  181. if (complete) {
  182. pView.timeEvent = ^(int eventCode) {
  183. complete(eventCode);
  184. };
  185. }
  186. return pView;
  187. }
  188. -(void)setUpView {
  189. self.frame = [UIScreen mainScreen].bounds;
  190. _timesArray = @[@"3",@"2",@"1"];
  191. [[UIApplication sharedApplication].delegate.window addSubview:self];
  192. [self show];
  193. }
  194. -(void)show {
  195. _timeL.tag = 0;
  196. _timeL.text = _timesArray[_timeL.tag];
  197. [_timeL.layer addAnimation:self.timeAnimation forKey:@"jy_scale"];
  198. }
  199. - (void)animationDidStop:(CAAnimation *)anim finished:(BOOL)flag {
  200. if (anim == [_timeL.layer animationForKey:@"jy_scale"]) {
  201. if (_timeL.tag == _timesArray.count - 1){
  202. //结束
  203. _timeL.text = @"";
  204. if (self.timeEvent) {
  205. self.timeEvent(0);
  206. }
  207. [self dismiss];
  208. }else {
  209. _timeL.tag ++;
  210. _timeL.text = _timesArray[_timeL.tag];
  211. [_timeL.layer addAnimation:self.timeAnimation forKey:@"jy_scale"];
  212. }
  213. }
  214. }
  215. - (CABasicAnimation *)timeAnimation {
  216. if (!_timeAnimation) {
  217. _timeAnimation = [CABasicAnimation animation];
  218. _timeAnimation.keyPath = @"transform.scale";
  219. _timeAnimation.removedOnCompletion = NO;
  220. _timeAnimation.fillMode = kCAFillModeForwards;
  221. _timeAnimation.delegate = self;
  222. _timeAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
  223. _timeAnimation.repeatCount = 1;
  224. _timeAnimation.fromValue = [NSNumber numberWithFloat:2.0f];
  225. _timeAnimation.toValue = [NSNumber numberWithFloat:0.2f];
  226. _timeAnimation.duration = 1.0f;
  227. }
  228. return _timeAnimation;
  229. }
  230. -(void)dismiss {
  231. [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
  232. [self removeFromSuperview];
  233. }
  234. #pragma mark 倒计时end
  235. @end