123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107 |
- //
- // 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
|