// // GuideView.m // GuideView // // Created by Lofty on 16/9/29. // Copyright © 2016年 Lofty. All rights reserved. // #import "GuideView.h" NSString *const kShowDSNewsGuideViewKey = @"kShowDSNewsGuideViewKey"; NSString *const kShowHaoHuoGuideViewKey = @"kShowHaoHuoGuideViewKey"; NSString *const kShowOfficalActivityGuideViewKey = @"kShowOfficalActivityGuideViewKey"; @interface GuideView () @end @implementation GuideView - (instancetype)init { self = [super init]; if (self) { [self setupView]; } return self; } - (void)setupView{ self.frame = [UIApplication sharedApplication].keyWindow.frame; if (self.backColor) { self.backgroundColor = self.backColor; }else{ self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7]; } [[UIApplication sharedApplication].keyWindow addSubview:self]; } - (void)dismissView{ __weak typeof(self) weakSelf = self; [UIView animateWithDuration:0.3 animations:^{ weakSelf.alpha = 0; } completion:^(BOOL finished) { [weakSelf removeFromSuperview]; if (weakSelf.completeBlock) { weakSelf.completeBlock(); } }]; } #pragma mark - 加入引导图单个元素 - (void)addMaskViewWithType:(NEW_FEATURE_TYPE_ENUM)type image:(NSString *)imageName andRect:(CGRect)rect{ if (type == NEW_FEATURE_TYPE_ENUM_IMG) { UIImageView *imageView = [[UIImageView alloc] init]; imageView.image = [UIImage imageNamed:imageName]; imageView.contentMode = UIViewContentModeScaleAspectFit; imageView.frame = rect; [self addSubview:imageView]; }else if (type == NEW_FEATURE_TYPE_ENUM_BTN){ UIButton *button = [[UIButton alloc] init]; [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal]; [button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; button.frame = rect; [self addSubview:button]; } } #pragma mark - 加入单张图片 - (void)addMaskView:(NSString *)imageName{ UIImageView *maskImageView = [[UIImageView alloc] init]; maskImageView.contentMode = UIViewContentModeScaleAspectFit; maskImageView.frame = self.frame; maskImageView.image = [UIImage imageNamed:imageName]; maskImageView.userInteractionEnabled = YES; [self addSubview:maskImageView]; UITapGestureRecognizer *dismissRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissView)]; dismissRec.numberOfTouchesRequired = 1; [maskImageView addGestureRecognizer:dismissRec]; } #pragma mark - 加入单张图片 - (void)addMaskView:(NSString *)imageName withImageRect:(CGRect)imageRect andBtnRect:(CGRect)btnRect{ UIImageView *maskImageView = [[UIImageView alloc] init]; maskImageView.contentMode = UIViewContentModeScaleAspectFit; maskImageView.frame = imageRect; maskImageView.image = [UIImage imageNamed:imageName]; [self addSubview:maskImageView]; UIButton *btnCancel = [[UIButton alloc] init]; [btnCancel addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside]; btnCancel.frame = btnRect; [self addSubview:btnCancel]; } - (void)addMaskView:(UIView *)view withRect:(CGRect)rect { view.frame = rect; [self addSubview:view]; } @end