// // FKWindowViewManager.m // FirstLink // // Created by ascii on 16/4/9. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKWindowViewManager.h" #import "UserDefaultManager.h" @interface FKWindowViewManager () @property (nonatomic, strong) NSMutableArray *floatViewArray; @property (nonatomic, strong) UIView *bgView; @end @implementation FKWindowViewManager + (FKWindowViewManager *)sharedManager { static FKWindowViewManager *sharedWindowViewManagerInstance = nil; static dispatch_once_t once_token; dispatch_once(&once_token, ^{ sharedWindowViewManagerInstance = [[self alloc] init]; }); return sharedWindowViewManagerInstance; } #pragma mark - Interface - (void)forceShowFloatView:(UIView *)view { if ([view isKindOfClass:[UIView class]]) { for (UIView *view in self.floatViewArray) { [view removeFromSuperview]; } [self.floatViewArray insertObject:view atIndex:0]; [self showFloatView:nil]; } } - (void)appendFloatView:(UIView *)view { [self.floatViewArray addObject:view]; } - (void)showFloatView:(UIColor *)bgColor { UIView *view = self.floatViewArray.firstObject; if (view && [view isKindOfClass:[UIView class]]) { UIWindow *window = [[[UIApplication sharedApplication] delegate] window]; self.bgView.backgroundColor = (bgColor ? bgColor : [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6]); self.bgView.frame = window.bounds; [self.bgView addSubview:view]; [window addSubview:self.bgView]; } } - (void)closeFloatView { [self.bgView removeFromSuperview]; UIView *view = self.floatViewArray.firstObject; if (view && [view isKindOfClass:[UIView class]]) { [view removeFromSuperview]; [self.floatViewArray removeObjectAtIndex:0]; } } - (BOOL)isNeedShowRegisterTip { NSString *ret = [[UserDefaultManager sharedManager] getUserDefaultObject:REGISTER_TIPVIEW_KEY]; if (![FKUserManager isUserLogin] && ![ret isEqualToString:[self currendDay]]) { return YES; } return NO; } - (void)completeShowRegisterTip { [[UserDefaultManager sharedManager] setUserDefaultObject:[self currendDay] key:REGISTER_TIPVIEW_KEY]; } // 格式:yy-mm-dd, 如2016-4-18 - (NSString *)currendDay { unsigned units = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay; NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDateComponents *components = [calendar components:units fromDate:[NSDate date]]; return [NSString stringWithFormat:@"%ld-%ld-%ld", (long)[components year], (long)[components month], (long)[components day]]; } #pragma mark - Property - (NSMutableArray *)floatViewArray { if (!_floatViewArray) { _floatViewArray = [NSMutableArray array]; } return _floatViewArray; } - (UIView *)bgView { if (!_bgView) { _bgView = [[UIView alloc] init]; } return _bgView; } @end