Nav apraksta

GuideView.m 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. //
  2. // GuideView.m
  3. // GuideView
  4. //
  5. // Created by Lofty on 16/9/29.
  6. // Copyright © 2016年 Lofty. All rights reserved.
  7. //
  8. #import "GuideView.h"
  9. NSString *const kShowDSNewsGuideViewKey = @"kShowDSNewsGuideViewKey";
  10. NSString *const kShowHaoHuoGuideViewKey = @"kShowHaoHuoGuideViewKey";
  11. NSString *const kShowOfficalActivityGuideViewKey = @"kShowOfficalActivityGuideViewKey";
  12. @interface GuideView ()
  13. @end
  14. @implementation GuideView
  15. - (instancetype)init
  16. {
  17. self = [super init];
  18. if (self) {
  19. [self setupView];
  20. }
  21. return self;
  22. }
  23. - (void)setupView{
  24. self.frame = [UIApplication sharedApplication].keyWindow.frame;
  25. if (self.backColor) {
  26. self.backgroundColor = self.backColor;
  27. }else{
  28. self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.7];
  29. }
  30. [[UIApplication sharedApplication].keyWindow addSubview:self];
  31. }
  32. - (void)dismissView{
  33. __weak typeof(self) weakSelf = self;
  34. [UIView animateWithDuration:0.3 animations:^{
  35. weakSelf.alpha = 0;
  36. } completion:^(BOOL finished) {
  37. [weakSelf removeFromSuperview];
  38. if (weakSelf.completeBlock) {
  39. weakSelf.completeBlock();
  40. }
  41. }];
  42. }
  43. #pragma mark - 加入引导图单个元素
  44. - (void)addMaskViewWithType:(NEW_FEATURE_TYPE_ENUM)type image:(NSString *)imageName andRect:(CGRect)rect{
  45. if (type == NEW_FEATURE_TYPE_ENUM_IMG) {
  46. UIImageView *imageView = [[UIImageView alloc] init];
  47. imageView.image = [UIImage imageNamed:imageName];
  48. imageView.contentMode = UIViewContentModeScaleAspectFit;
  49. imageView.frame = rect;
  50. [self addSubview:imageView];
  51. }else if (type == NEW_FEATURE_TYPE_ENUM_BTN){
  52. UIButton *button = [[UIButton alloc] init];
  53. [button setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
  54. [button addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
  55. button.frame = rect;
  56. [self addSubview:button];
  57. }
  58. }
  59. #pragma mark - 加入单张图片
  60. - (void)addMaskView:(NSString *)imageName{
  61. UIImageView *maskImageView = [[UIImageView alloc] init];
  62. maskImageView.contentMode = UIViewContentModeScaleAspectFit;
  63. maskImageView.frame = self.frame;
  64. maskImageView.image = [UIImage imageNamed:imageName];
  65. maskImageView.userInteractionEnabled = YES;
  66. [self addSubview:maskImageView];
  67. UITapGestureRecognizer *dismissRec = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissView)];
  68. dismissRec.numberOfTouchesRequired = 1;
  69. [maskImageView addGestureRecognizer:dismissRec];
  70. }
  71. #pragma mark - 加入单张图片
  72. - (void)addMaskView:(NSString *)imageName withImageRect:(CGRect)imageRect andBtnRect:(CGRect)btnRect{
  73. UIImageView *maskImageView = [[UIImageView alloc] init];
  74. maskImageView.contentMode = UIViewContentModeScaleAspectFit;
  75. maskImageView.frame = imageRect;
  76. maskImageView.image = [UIImage imageNamed:imageName];
  77. [self addSubview:maskImageView];
  78. UIButton *btnCancel = [[UIButton alloc] init];
  79. [btnCancel addTarget:self action:@selector(dismissView) forControlEvents:UIControlEventTouchUpInside];
  80. btnCancel.frame = btnRect;
  81. [self addSubview:btnCancel];
  82. }
  83. - (void)addMaskView:(UIView *)view withRect:(CGRect)rect {
  84. view.frame = rect;
  85. [self addSubview:view];
  86. }
  87. @end