// // FKDirectBuyRiskView.m // FirstLink // // Created by jack on 16/1/12. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKDirectBuyRiskView.h" #import "GuideView.h" #import "FKTargetConfigUtil.h" #define kContentAnimDuration 0.4f #define kVertLineAnimDuration 0.2f #define kRiskViewAnimDuration 0.2f static NSString *SUBMIT_PROPMT_IS_SHOW_FIRST_KEY = @"SUBMIT_PROPMT_IS_SHOW_FIRST_KEY"; @interface FKDirectBuyRiskView () @property (nonatomic, strong) UIButton *cancelBtn; @property (nonatomic, strong) UIView *contentView; @property (nonatomic, strong) UIView *vertLine; @end @implementation FKDirectBuyRiskView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7]; } return self; } - (void)addAllSubviews{ [self addSubview:self.cancelBtn]; [self.layer addSublayer:self.vertLine.layer]; [self.layer addSublayer:self.contentView.layer]; if (CGRectIsEmpty(self.bounds)) return; CGFloat width = CGRectGetWidth(self.bounds); CGFloat lineH = 50; CGFloat contentH = 270; if (UISCREENWIDTH <= 320){ contentH = 290; } self.cancelBtn.bounds = CGRectMake(0, 0, 60, 60); self.cancelBtn.center = CGPointMake(width - 35, IS_IPHONE_X ? 66 : 42); self.vertLine.layer.anchorPoint = CGPointMake(0.5, 0); self.vertLine.layer.position = CGPointMake(CGRectGetMidX(self.cancelBtn.frame), CGRectGetMidY(self.cancelBtn.frame) + 15); self.vertLine.bounds = CGRectMake(0, 0, 1, lineH); self.contentView.layer.anchorPoint = CGPointMake(0.5, 0); self.contentView.layer.position = CGPointMake(width / 2.0f, CGRectGetMaxY(self.vertLine.frame)); self.contentView.bounds = CGRectMake(0, 0, width - 50, contentH); [self layoutContentView]; } - (void)layoutContentView{ UIImageView *iconImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"loudSpeaker"]]; UIImageView *thunderImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"risk_thunder"]]; UILabel *titleLabel = ({ UILabel *label = [[UILabel alloc]init]; label.textColor = UIColorFromRGB(0xf85a5a); label.font = [UIFont systemFontOfSize:16]; label.text = @"直邮订单温馨提示"; [label setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal]; label; }); NSString *text = [NSString stringWithFormat:@"Hi,亲爱的%@用户,订单一旦付款便无法修改或取消,请您仔细核对订单信息,阅读以下提示后谨慎购买:", [FKTargetConfigUtil appName]]; UILabel *contentLabel1 = [self commonLabelForText:text textColor:UIColorFromRGB(0x999999)]; NSString *text2 = [NSString stringWithFormat:@"1.%@为您在海外网站下单成功后,原则上不支持退款。", [FKTargetConfigUtil appName]]; UILabel *contentLabel2 = [self commonLabelForText:text2 textColor:UIColorFromRGB(0x333333)]; UILabel *contentLabel3 = [self commonLabelForText:@"2.在海外网站帮你下单时,如遇网站砍单,系统将自动处理相应的退款。" textColor:UIColorFromRGB(0x333333)]; [self.contentView addSubview:thunderImgView]; [self.contentView addSubview:iconImgView]; [self.contentView addSubview:titleLabel]; [self.contentView addSubview:contentLabel1]; [self.contentView addSubview:contentLabel2]; [self.contentView addSubview:contentLabel3]; [thunderImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView); make.bottom.equalTo(self.contentView).offset(- 35); }]; CGFloat titleRightMove = 5; if (IS_IPHONE_5){ titleRightMove = 15; } [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.centerX.equalTo(self.contentView).offset(titleRightMove); make.top.equalTo(self.contentView).offset(35); }]; [iconImgView mas_makeConstraints:^(MASConstraintMaker *make) { make.right.equalTo(titleLabel.mas_left).offset(- 8); make.centerY.equalTo(titleLabel); }]; [contentLabel1 mas_makeConstraints:^(MASConstraintMaker *make) { make.left.equalTo(self.contentView).offset(25); make.right.equalTo(self.contentView).offset(- 25); make.top.equalTo(iconImgView.mas_bottom).offset(20); }]; [contentLabel2 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(contentLabel1.mas_bottom).offset(19); make.left.right.equalTo(contentLabel1); }]; [contentLabel3 mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(contentLabel2.mas_bottom).offset(13); make.left.right.equalTo(contentLabel1); }]; [self.contentView setNeedsLayout]; [self.contentView layoutIfNeeded]; } - (UILabel *)commonLabelForText:(NSString *)text textColor:(UIColor *)textColor{ UILabel *label = [[UILabel alloc]init]; label.textColor = textColor; label.font = [UIFont systemFontOfSize:14]; label.numberOfLines = 0; if (text.length) { label.attributedText = [FLStringHelper attStringWithText:text color:UIColorFromRGB(0x666666) font:[UIFont systemFontOfSize:14] lineSpace:3.0f]; } return label; } - (void)showInView:(UIView *)view{ if (!view || CGRectIsEmpty(view.bounds)) return; self.frame = view.bounds; [view addSubview:self]; [self addAllSubviews]; CGFloat contentH = CGRectGetHeight(self.contentView.bounds); CGFloat contentW = CGRectGetWidth(self.contentView.bounds); CGFloat vertLineH = CGRectGetHeight(self.vertLine.bounds); CGFloat vertLinew = CGRectGetWidth(self.vertLine.bounds); self.alpha = 0.0f; self.contentView.bounds = CGRectMake(0, 0, contentW, 0); self.vertLine.bounds = CGRectMake(0, 0, vertLinew, 0); WeakSelf(weakSelf); [UIView animateWithDuration:kRiskViewAnimDuration animations:^{ weakSelf.alpha = 1.0f; } completion:^(BOOL finished) { [UIView animateWithDuration:kVertLineAnimDuration animations:^{ weakSelf.vertLine.bounds = CGRectMake(0, 0, vertLinew, vertLineH); } completion:^(BOOL finished) { [UIView animateWithDuration:kContentAnimDuration animations:^{ weakSelf.contentView.bounds = CGRectMake(0, 0, contentW, contentH); }]; }]; }]; } #pragma mark - action - (void)clickCancelBtn:(UIButton *)button{ CGFloat contentW = CGRectGetWidth(self.contentView.bounds); CGFloat vertLinew = CGRectGetWidth(self.vertLine.bounds); self.alpha = 1.0f; WeakSelf(weakSelf); [UIView animateWithDuration:kContentAnimDuration animations:^{ weakSelf.contentView.bounds = CGRectMake(0, 0, contentW, 0); } completion:^(BOOL finished) { [UIView animateWithDuration:kVertLineAnimDuration animations:^{ weakSelf.vertLine.bounds = CGRectMake(0, 0, vertLinew, 0); } completion:^(BOOL finished) { [UIView animateWithDuration:kVertLineAnimDuration animations:^{ weakSelf.alpha = 0.0f; } completion:^(BOOL finished) { [weakSelf removeFromSuperview]; [self showGuideView]; }]; }]; }]; } - (CGFloat)guideViewHeight{ if (IS_IPHONE_5) { return 269; } else if(IS_IPHONE_6){ return 320; } else if(IS_IPHONE_6P){ return 350; } else if (IS_IPHONE_X) { return 360; } return 350; } - (void)showGuideView{ BOOL res = [[[NSUserDefaults standardUserDefaults] objectForKey:SUBMIT_PROPMT_IS_SHOW_FIRST_KEY] boolValue]; if (!res && !IS_IPHONE_4 && !IS_IPHONE_5) { GuideView *guideView = [[GuideView alloc] init]; [guideView addMaskView:@"guide_newpeople_img" withImageRect:CGRectMake(15, UISCREENHEIGH-20-[self guideViewHeight], UISCREENWIDTH-30, [self guideViewHeight]) andBtnRect:CGRectMake(UISCREENWIDTH/2-40, UISCREENHEIGH-20-[self guideViewHeight], 120, 40)]; [[NSUserDefaults standardUserDefaults] setBool:YES forKey:SUBMIT_PROPMT_IS_SHOW_FIRST_KEY]; [[NSUserDefaults standardUserDefaults] synchronize]; } } #pragma mark - property - (UIButton *)cancelBtn{ if (_cancelBtn == nil) { _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_cancelBtn setImage:[UIImage imageNamed:@"blackCross_cancelBtn"] forState:UIControlStateNormal]; [_cancelBtn addTarget:self action:@selector(clickCancelBtn:) forControlEvents:UIControlEventTouchUpInside]; } return _cancelBtn; } - (UIView *)contentView{ if (_contentView == nil) { _contentView = [[UIView alloc]init]; _contentView.backgroundColor = [UIColor whiteColor]; _contentView.layer.cornerRadius = 7; _contentView.clipsToBounds = YES; } return _contentView; } - (UIView *)vertLine{ if (_vertLine == nil) { _vertLine = [[UIView alloc]init]; _vertLine.backgroundColor = [UIColor whiteColor]; } return _vertLine; } @end