1. .h
@interface TCHelpPageManager : NSObject
+ (instancetype)manager;
/**
* 社区帮助页
*/
- (void)showCommunityHelpPageWithCompleted:(TCCompleteBlock)complete;
@end
#define CheckHasOpend( t ) if (HasOpendHelpPage( t )) {if (self.currentCompleteBlock) {self.currentCompleteBlock(self.currentHelpPage);}return;}
@interface TCHelpPageManager ()
@property (nonatomic, assign) TCHelpPageType currentHelpPage;
@property (nonatomic, copy) TCCompleteBlock currentCompleteBlock;
@end
static TCHelpPageManager *manager = nil;
@implementation TCHelpPageManager
/** * 判断 某个帮助页是否展示过 */
CG_INLINE BOOL HasOpendHelpPage(TCHelpPageType type) {
return [TCHelpPageManager hasOpendHelpPageWithHelpPageType:type];
};
/** * 改变 某个帮助页的打开状态为TRUE */
CG_INLINE BOOL InsertHelpPage(TCHelpPageType type) {
return [TCHelpPageManager insertOpendPage:type];
};
+ (instancetype)manager
{
static dispatch_once_t once;
dispatch_once(&once, ^{
manager = [[self alloc] init];
});
return manager;
}
/**
服务界面队长卡帮助页
*/
/*卡*/
- (void)showServiceCardWithCompleted:(TCCompleteBlock)complete
{
self.currentHelpPage = TCHelpPageType_ServiceCard;
self.currentCompleteBlock = complete;
CheckHasOpend(TCHelpPageType_ServiceCard);
UIView *shadeView = [self getBackShadeView];
UIImageView *topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"Captain_card_online"]];
[shadeView addSubview:topImageView];
[topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(shadeView.mas_right).offset(-TCWidth(30));
make.top.equalTo(shadeView.mas_top).offset(TCAdHeight(218));
make.width.mas_equalTo(TCWidth(270));
make.height.mas_equalTo(TCHeight(184));
}];
UIImageView *bottomImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"i_know_btn"]];
[shadeView addSubview:bottomImageView];
bottomImageView.userInteractionEnabled = YES;
[bottomImageView mas_makeConstraints:^(MASConstraintMaker *make) {
make.right.equalTo(shadeView.mas_right).offset(-TCWidth(71));
make.top.equalTo(topImageView.mas_bottom).offset(TCHeight(73));
make.width.mas_equalTo(TCWidth(115));
make.height.mas_equalTo(TCHeight(37));
}];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shadeViewAction:)];
[bottomImageView addGestureRecognizer:tap];
}
/** [私有方法]
* Action Deal
*/
- (void)shadeViewAction:(UITapGestureRecognizer *)ges
{
InsertHelpPage(self.currentHelpPage);
[ges.view.superview removeFromSuperview];
if (self.currentCompleteBlock) {
self.currentCompleteBlock(self.currentHelpPage);
}
}
/** [私有方法]
* @param complete : 统一注册complete
*/
- (UIView *)getBackShadeView
{
UIView *shadeView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
shadeView.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.6];
shadeView.userInteractionEnabled = YES;
// [shadeView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shadeViewAction:)]];
[[TCToolBaseClass getRootView] addSubview:shadeView];
return shadeView;
}
* 判断 某个帮助页是否展示过
*/
+ (BOOL)hasOpendHelpPageWithHelpPageType:(TCHelpPageType)type
{
NSMutableArray *opendPages = [NSMutableArray arrayWithArray:[self getOpendHelpPage]];
return [opendPages containsObject:[NSString stringWithFormat:@"%d", type]];
}
/** [私有方法]
* 改变 某个帮助页的打开状态为TRUE
*/
+ (BOOL)insertOpendPage:(TCHelpPageType)type
{
NSMutableArray *opendPages = [NSMutableArray arrayWithArray:[self getOpendHelpPage]];
[opendPages addObject:[NSString stringWithFormat:@"%d", type]];
[[NSUserDefaults standardUserDefaults] setObject:opendPages forKey:kOpendHelpPages];
return [[NSUserDefaults standardUserDefaults] synchronize];
}