Keine Beschreibung

FKWindowViewManager.m 3.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. //
  2. // FKWindowViewManager.m
  3. // FirstLink
  4. //
  5. // Created by ascii on 16/4/9.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKWindowViewManager.h"
  9. #import "UserDefaultManager.h"
  10. @interface FKWindowViewManager ()
  11. @property (nonatomic, strong) NSMutableArray *floatViewArray;
  12. @property (nonatomic, strong) UIView *bgView;
  13. @end
  14. @implementation FKWindowViewManager
  15. + (FKWindowViewManager *)sharedManager {
  16. static FKWindowViewManager *sharedWindowViewManagerInstance = nil;
  17. static dispatch_once_t once_token;
  18. dispatch_once(&once_token, ^{
  19. sharedWindowViewManagerInstance = [[self alloc] init];
  20. });
  21. return sharedWindowViewManagerInstance;
  22. }
  23. #pragma mark - Interface
  24. - (void)forceShowFloatView:(UIView *)view {
  25. if ([view isKindOfClass:[UIView class]]) {
  26. for (UIView *view in self.floatViewArray) {
  27. [view removeFromSuperview];
  28. }
  29. [self.floatViewArray insertObject:view atIndex:0];
  30. [self showFloatView:nil];
  31. }
  32. }
  33. - (void)appendFloatView:(UIView *)view {
  34. [self.floatViewArray addObject:view];
  35. }
  36. - (void)showFloatView:(UIColor *)bgColor {
  37. UIView *view = self.floatViewArray.firstObject;
  38. if (view && [view isKindOfClass:[UIView class]]) {
  39. UIWindow *window = [[[UIApplication sharedApplication] delegate] window];
  40. self.bgView.backgroundColor = (bgColor ? bgColor : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6]);
  41. self.bgView.frame = window.bounds;
  42. [self.bgView addSubview:view];
  43. [window addSubview:self.bgView];
  44. }
  45. }
  46. - (void)closeFloatView {
  47. [self.bgView removeFromSuperview];
  48. UIView *view = self.floatViewArray.firstObject;
  49. if (view && [view isKindOfClass:[UIView class]]) {
  50. [view removeFromSuperview];
  51. [self.floatViewArray removeObjectAtIndex:0];
  52. }
  53. }
  54. - (BOOL)isNeedShowRegisterTip {
  55. NSString *ret = [[UserDefaultManager sharedManager] getUserDefaultObject:REGISTER_TIPVIEW_KEY];
  56. if (![FKUserManager isUserLogin] && ![ret isEqualToString:[self currendDay]]) {
  57. return YES;
  58. }
  59. return NO;
  60. }
  61. - (void)completeShowRegisterTip {
  62. [[UserDefaultManager sharedManager] setUserDefaultObject:[self currendDay]
  63. key:REGISTER_TIPVIEW_KEY];
  64. }
  65. // 格式:yy-mm-dd, 如2016-4-18
  66. - (NSString *)currendDay {
  67. unsigned units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
  68. NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
  69. NSDateComponents *components = [calendar components:units fromDate:[NSDate date]];
  70. return [NSString stringWithFormat:@"%ld-%ld-%ld", (long)[components year], (long)[components month], (long)[components day]];
  71. }
  72. #pragma mark - Property
  73. - (NSMutableArray *)floatViewArray {
  74. if (!_floatViewArray) {
  75. _floatViewArray = [NSMutableArray array];
  76. }
  77. return _floatViewArray;
  78. }
  79. - (UIView *)bgView {
  80. if (!_bgView) {
  81. _bgView = [[UIView alloc] init];
  82. }
  83. return _bgView;
  84. }
  85. @end