|
| 1 | +// |
| 2 | +// RewardTipManager.m |
| 3 | +// Coding_iOS |
| 4 | +// |
| 5 | +// Created by Ease on 2016/12/14. |
| 6 | +// Copyright © 2016年 Coding. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +#import "RewardTipManager.h" |
| 10 | +#import "PointRecordsViewController.h" |
| 11 | +#import "Login.h" |
| 12 | + |
| 13 | +@interface RewardTipManager () |
| 14 | +@property (strong, nonatomic) NSString *title, *rewardPoint; |
| 15 | + |
| 16 | +@property (strong, nonatomic) UIView *bgView, *contentView; |
| 17 | +@property (strong, nonatomic) UIImageView *logoImgV; |
| 18 | +@property (strong, nonatomic) UILabel *titleL, *rewardPointL; |
| 19 | +@property (strong, nonatomic) UIButton *closeBtn, *knowMoreBtn; |
| 20 | +@end |
| 21 | + |
| 22 | +@implementation RewardTipManager |
| 23 | ++ (instancetype)shareManager{ |
| 24 | + static RewardTipManager *shared_manager = nil; |
| 25 | + static dispatch_once_t pred; |
| 26 | + dispatch_once(&pred, ^{ |
| 27 | + shared_manager = [[self alloc] init]; |
| 28 | + }); |
| 29 | + return shared_manager; |
| 30 | +} |
| 31 | + |
| 32 | ++ (void)showTipWithTitle:(NSString *)title rewardPoint:(NSString *)rewardPoint{ |
| 33 | + if (![Login isLogin]) { |
| 34 | + return; |
| 35 | + } |
| 36 | + RewardTipManager *manager = [self shareManager]; |
| 37 | + manager.title = title; |
| 38 | + manager.rewardPoint = rewardPoint; |
| 39 | + [manager p_show]; |
| 40 | +} |
| 41 | + |
| 42 | +- (instancetype)init{ |
| 43 | + self = [super init]; |
| 44 | + if (self) { |
| 45 | + //层级关系 |
| 46 | + _bgView = [UIView new]; |
| 47 | + _contentView = [UIView new]; |
| 48 | + |
| 49 | + _logoImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"reward_tip_logo"]]; |
| 50 | + _titleL = [UILabel labelWithFont:[UIFont boldSystemFontOfSize:18] textColor:[UIColor colorWithHexString:@"0x222222"]]; |
| 51 | + _rewardPointL = [UILabel labelWithSystemFontSize:15 textColorHexString:@"0x222222"]; |
| 52 | + _knowMoreBtn = ({ |
| 53 | + UIButton *button = [UIButton new]; |
| 54 | + button.backgroundColor = kColorBrandGreen; |
| 55 | + [button doBorderWidth:0 color:nil cornerRadius:4]; |
| 56 | + button.titleLabel.font = [UIFont systemFontOfSize:18]; |
| 57 | + [button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; |
| 58 | + [button setTitle:@"了解码币" forState:UIControlStateNormal]; |
| 59 | + [button addTarget:self action:@selector(knowMoreBtnClicked) forControlEvents:UIControlEventTouchUpInside]; |
| 60 | + button; |
| 61 | + }); |
| 62 | + _closeBtn = ({ |
| 63 | + UIButton *button = [UIButton new]; |
| 64 | + button.backgroundColor = kColorTableSectionBg; |
| 65 | + [button doBorderWidth:1.0 color:kColorDDD cornerRadius:4]; |
| 66 | + button.titleLabel.font = [UIFont systemFontOfSize:18]; |
| 67 | + [button setTitleColor:kColor666 forState:UIControlStateNormal]; |
| 68 | + [button setTitle:@"知道了" forState:UIControlStateNormal]; |
| 69 | + [button addTarget:self action:@selector(p_dismiss) forControlEvents:UIControlEventTouchUpInside]; |
| 70 | + button; |
| 71 | + }); |
| 72 | + [_contentView addSubview:_logoImgV]; |
| 73 | + [_contentView addSubview:_titleL]; |
| 74 | + [_contentView addSubview:_rewardPointL]; |
| 75 | + [_contentView addSubview:_knowMoreBtn]; |
| 76 | + [_contentView addSubview:_closeBtn]; |
| 77 | + [_bgView addSubview:_contentView]; |
| 78 | + //属性设置 |
| 79 | + _contentView.backgroundColor = kColorTableSectionBg; |
| 80 | + _contentView.layer.masksToBounds = YES; |
| 81 | + _contentView.layer.cornerRadius = 6; |
| 82 | + _rewardPointL.textAlignment = _titleL.textAlignment = NSTextAlignmentCenter; |
| 83 | + _titleL.numberOfLines = 0; |
| 84 | + //位置大小 |
| 85 | + [_contentView mas_makeConstraints:^(MASConstraintMaker *make) { |
| 86 | + make.width.mas_equalTo(270); |
| 87 | + make.center.equalTo(_bgView); |
| 88 | + }]; |
| 89 | + [_logoImgV mas_makeConstraints:^(MASConstraintMaker *make) { |
| 90 | + make.size.mas_equalTo(CGSizeMake(88, 67)); |
| 91 | + make.centerX.equalTo(_contentView); |
| 92 | + make.top.equalTo(_contentView).mas_offset(30); |
| 93 | + }]; |
| 94 | + [_titleL mas_makeConstraints:^(MASConstraintMaker *make) { |
| 95 | + make.top.equalTo(_logoImgV.mas_bottom).offset(30); |
| 96 | + make.left.equalTo(_contentView).offset(15); |
| 97 | + make.right.equalTo(_contentView).offset(-15); |
| 98 | + }]; |
| 99 | + [_rewardPointL mas_makeConstraints:^(MASConstraintMaker *make) { |
| 100 | + make.top.equalTo(_titleL.mas_bottom).offset(10); |
| 101 | + make.left.right.equalTo(_titleL); |
| 102 | + }]; |
| 103 | + [_knowMoreBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
| 104 | + make.top.equalTo(_rewardPointL.mas_bottom).offset(20); |
| 105 | + make.left.equalTo(_contentView).offset(20); |
| 106 | + make.bottom.equalTo(_contentView).offset(-20); |
| 107 | + make.right.equalTo(_closeBtn.mas_left).offset(-10); |
| 108 | + make.width.equalTo(_closeBtn); |
| 109 | + make.height.mas_equalTo(44); |
| 110 | + }]; |
| 111 | + [_closeBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
| 112 | + make.right.equalTo(_contentView).offset(-20); |
| 113 | + make.top.bottom.equalTo(_knowMoreBtn); |
| 114 | + }]; |
| 115 | + //关联事件 |
| 116 | + [_bgView bk_whenTapped:^{ |
| 117 | + [self p_dismiss]; |
| 118 | + }]; |
| 119 | + } |
| 120 | + return self; |
| 121 | +} |
| 122 | + |
| 123 | +- (void)setTitle:(NSString *)title{ |
| 124 | + _title = title; |
| 125 | + _titleL.text = _title; |
| 126 | +} |
| 127 | + |
| 128 | +- (void)setRewardPoint:(NSString *)rewardPoint{ |
| 129 | + _rewardPoint = rewardPoint; |
| 130 | + _rewardPointL.text = [NSString stringWithFormat:@"获得 %@ MB 的奖励", _rewardPoint]; |
| 131 | +} |
| 132 | + |
| 133 | +- (void)knowMoreBtnClicked{ |
| 134 | + PointRecordsViewController *vc = [PointRecordsViewController new]; |
| 135 | + [BaseViewController goToVC:vc]; |
| 136 | + [self p_dismiss]; |
| 137 | +} |
| 138 | + |
| 139 | +- (void)p_show{ |
| 140 | + //初始状态 |
| 141 | + _bgView.backgroundColor = [UIColor clearColor]; |
| 142 | + _contentView.alpha = 0; |
| 143 | + _bgView.frame = kScreen_Bounds; |
| 144 | + |
| 145 | + [kKeyWindow addSubview:_bgView]; |
| 146 | + [UIView animateWithDuration:0.3 animations:^{ |
| 147 | + _bgView.backgroundColor = [UIColor colorWithWhite:0 alpha:0.6]; |
| 148 | + _contentView.alpha = 1; |
| 149 | + } completion:nil]; |
| 150 | +} |
| 151 | + |
| 152 | +- (void)p_dismiss{ |
| 153 | + [UIView animateWithDuration:0.3 animations:^{ |
| 154 | + _bgView.backgroundColor = [UIColor clearColor]; |
| 155 | + _contentView.alpha = 0; |
| 156 | + } completion:^(BOOL finished) { |
| 157 | + [_bgView removeFromSuperview]; |
| 158 | + }]; |
| 159 | +} |
| 160 | + |
| 161 | +@end |
0 commit comments