説明なし

FKDirectBuyRiskView.m 9.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. //
  2. // FKDirectBuyRiskView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/1/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKDirectBuyRiskView.h"
  9. #import "GuideView.h"
  10. #import "FKTargetConfigUtil.h"
  11. #define kContentAnimDuration 0.4f
  12. #define kVertLineAnimDuration 0.2f
  13. #define kRiskViewAnimDuration 0.2f
  14. static NSString *SUBMIT_PROPMT_IS_SHOW_FIRST_KEY = @"SUBMIT_PROPMT_IS_SHOW_FIRST_KEY";
  15. @interface FKDirectBuyRiskView ()
  16. @property (nonatomic, strong) UIButton *cancelBtn;
  17. @property (nonatomic, strong) UIView *contentView;
  18. @property (nonatomic, strong) UIView *vertLine;
  19. @end
  20. @implementation FKDirectBuyRiskView
  21. - (instancetype)initWithFrame:(CGRect)frame{
  22. if (self = [super initWithFrame:frame]) {
  23. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.7];
  24. }
  25. return self;
  26. }
  27. - (void)addAllSubviews{
  28. [self addSubview:self.cancelBtn];
  29. [self.layer addSublayer:self.vertLine.layer];
  30. [self.layer addSublayer:self.contentView.layer];
  31. if (CGRectIsEmpty(self.bounds)) return;
  32. CGFloat width = CGRectGetWidth(self.bounds);
  33. CGFloat lineH = 50;
  34. CGFloat contentH = 270;
  35. if (UISCREENWIDTH <= 320){
  36. contentH = 290;
  37. }
  38. self.cancelBtn.bounds = CGRectMake(0, 0, 60, 60);
  39. self.cancelBtn.center = CGPointMake(width - 35, IS_IPHONE_X ? 66 : 42);
  40. self.vertLine.layer.anchorPoint = CGPointMake(0.5, 0);
  41. self.vertLine.layer.position = CGPointMake(CGRectGetMidX(self.cancelBtn.frame), CGRectGetMidY(self.cancelBtn.frame) + 15);
  42. self.vertLine.bounds = CGRectMake(0, 0, 1, lineH);
  43. self.contentView.layer.anchorPoint = CGPointMake(0.5, 0);
  44. self.contentView.layer.position = CGPointMake(width / 2.0f, CGRectGetMaxY(self.vertLine.frame));
  45. self.contentView.bounds = CGRectMake(0, 0, width - 50, contentH);
  46. [self layoutContentView];
  47. }
  48. - (void)layoutContentView{
  49. UIImageView *iconImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"loudSpeaker"]];
  50. UIImageView *thunderImgView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"risk_thunder"]];
  51. UILabel *titleLabel = ({
  52. UILabel *label = [[UILabel alloc]init];
  53. label.textColor = UIColorFromRGB(0xf85a5a);
  54. label.font = [UIFont systemFontOfSize:16];
  55. label.text = @"直邮订单温馨提示";
  56. [label setContentHuggingPriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  57. label;
  58. });
  59. NSString *text = [NSString stringWithFormat:@"Hi,亲爱的%@用户,订单一旦付款便无法修改或取消,请您仔细核对订单信息,阅读以下提示后谨慎购买:", [FKTargetConfigUtil appName]];
  60. UILabel *contentLabel1 = [self commonLabelForText:text textColor:UIColorFromRGB(0x999999)];
  61. NSString *text2 = [NSString stringWithFormat:@"1.%@为您在海外网站下单成功后,原则上不支持退款。", [FKTargetConfigUtil appName]];
  62. UILabel *contentLabel2 = [self commonLabelForText:text2 textColor:UIColorFromRGB(0x333333)];
  63. UILabel *contentLabel3 = [self commonLabelForText:@"2.在海外网站帮你下单时,如遇网站砍单,系统将自动处理相应的退款。" textColor:UIColorFromRGB(0x333333)];
  64. [self.contentView addSubview:thunderImgView];
  65. [self.contentView addSubview:iconImgView];
  66. [self.contentView addSubview:titleLabel];
  67. [self.contentView addSubview:contentLabel1];
  68. [self.contentView addSubview:contentLabel2];
  69. [self.contentView addSubview:contentLabel3];
  70. [thunderImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  71. make.centerX.equalTo(self.contentView);
  72. make.bottom.equalTo(self.contentView).offset(- 35);
  73. }];
  74. CGFloat titleRightMove = 5;
  75. if (IS_IPHONE_5){
  76. titleRightMove = 15;
  77. }
  78. [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.centerX.equalTo(self.contentView).offset(titleRightMove);
  80. make.top.equalTo(self.contentView).offset(35);
  81. }];
  82. [iconImgView mas_makeConstraints:^(MASConstraintMaker *make) {
  83. make.right.equalTo(titleLabel.mas_left).offset(- 8);
  84. make.centerY.equalTo(titleLabel);
  85. }];
  86. [contentLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
  87. make.left.equalTo(self.contentView).offset(25);
  88. make.right.equalTo(self.contentView).offset(- 25);
  89. make.top.equalTo(iconImgView.mas_bottom).offset(20);
  90. }];
  91. [contentLabel2 mas_makeConstraints:^(MASConstraintMaker *make) {
  92. make.top.equalTo(contentLabel1.mas_bottom).offset(19);
  93. make.left.right.equalTo(contentLabel1);
  94. }];
  95. [contentLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
  96. make.top.equalTo(contentLabel2.mas_bottom).offset(13);
  97. make.left.right.equalTo(contentLabel1);
  98. }];
  99. [self.contentView setNeedsLayout];
  100. [self.contentView layoutIfNeeded];
  101. }
  102. - (UILabel *)commonLabelForText:(NSString *)text textColor:(UIColor *)textColor{
  103. UILabel *label = [[UILabel alloc]init];
  104. label.textColor = textColor;
  105. label.font = [UIFont systemFontOfSize:14];
  106. label.numberOfLines = 0;
  107. if (text.length) {
  108. label.attributedText = [FLStringHelper attStringWithText:text
  109. color:UIColorFromRGB(0x666666)
  110. font:[UIFont systemFontOfSize:14]
  111. lineSpace:3.0f];
  112. }
  113. return label;
  114. }
  115. - (void)showInView:(UIView *)view{
  116. if (!view || CGRectIsEmpty(view.bounds)) return;
  117. self.frame = view.bounds;
  118. [view addSubview:self];
  119. [self addAllSubviews];
  120. CGFloat contentH = CGRectGetHeight(self.contentView.bounds);
  121. CGFloat contentW = CGRectGetWidth(self.contentView.bounds);
  122. CGFloat vertLineH = CGRectGetHeight(self.vertLine.bounds);
  123. CGFloat vertLinew = CGRectGetWidth(self.vertLine.bounds);
  124. self.alpha = 0.0f;
  125. self.contentView.bounds = CGRectMake(0, 0, contentW, 0);
  126. self.vertLine.bounds = CGRectMake(0, 0, vertLinew, 0);
  127. WeakSelf(weakSelf);
  128. [UIView animateWithDuration:kRiskViewAnimDuration animations:^{
  129. weakSelf.alpha = 1.0f;
  130. } completion:^(BOOL finished) {
  131. [UIView animateWithDuration:kVertLineAnimDuration animations:^{
  132. weakSelf.vertLine.bounds = CGRectMake(0, 0, vertLinew, vertLineH);
  133. } completion:^(BOOL finished) {
  134. [UIView animateWithDuration:kContentAnimDuration animations:^{
  135. weakSelf.contentView.bounds = CGRectMake(0, 0, contentW, contentH);
  136. }];
  137. }];
  138. }];
  139. }
  140. #pragma mark - action
  141. - (void)clickCancelBtn:(UIButton *)button{
  142. CGFloat contentW = CGRectGetWidth(self.contentView.bounds);
  143. CGFloat vertLinew = CGRectGetWidth(self.vertLine.bounds);
  144. self.alpha = 1.0f;
  145. WeakSelf(weakSelf);
  146. [UIView animateWithDuration:kContentAnimDuration animations:^{
  147. weakSelf.contentView.bounds = CGRectMake(0, 0, contentW, 0);
  148. } completion:^(BOOL finished) {
  149. [UIView animateWithDuration:kVertLineAnimDuration animations:^{
  150. weakSelf.vertLine.bounds = CGRectMake(0, 0, vertLinew, 0);
  151. } completion:^(BOOL finished) {
  152. [UIView animateWithDuration:kVertLineAnimDuration animations:^{
  153. weakSelf.alpha = 0.0f;
  154. } completion:^(BOOL finished) {
  155. [weakSelf removeFromSuperview];
  156. [self showGuideView];
  157. }];
  158. }];
  159. }];
  160. }
  161. - (CGFloat)guideViewHeight{
  162. if (IS_IPHONE_5) {
  163. return 269;
  164. } else if(IS_IPHONE_6){
  165. return 320;
  166. } else if(IS_IPHONE_6P){
  167. return 350;
  168. } else if (IS_IPHONE_X) {
  169. return 360;
  170. }
  171. return 350;
  172. }
  173. - (void)showGuideView{
  174. BOOL res = [[[NSUserDefaults standardUserDefaults] objectForKey:SUBMIT_PROPMT_IS_SHOW_FIRST_KEY] boolValue];
  175. if (!res && !IS_IPHONE_4 && !IS_IPHONE_5) {
  176. GuideView *guideView = [[GuideView alloc] init];
  177. [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)];
  178. [[NSUserDefaults standardUserDefaults] setBool:YES forKey:SUBMIT_PROPMT_IS_SHOW_FIRST_KEY];
  179. [[NSUserDefaults standardUserDefaults] synchronize];
  180. }
  181. }
  182. #pragma mark - property
  183. - (UIButton *)cancelBtn{
  184. if (_cancelBtn == nil) {
  185. _cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  186. [_cancelBtn setImage:[UIImage imageNamed:@"blackCross_cancelBtn"] forState:UIControlStateNormal];
  187. [_cancelBtn addTarget:self action:@selector(clickCancelBtn:) forControlEvents:UIControlEventTouchUpInside];
  188. }
  189. return _cancelBtn;
  190. }
  191. - (UIView *)contentView{
  192. if (_contentView == nil) {
  193. _contentView = [[UIView alloc]init];
  194. _contentView.backgroundColor = [UIColor whiteColor];
  195. _contentView.layer.cornerRadius = 7;
  196. _contentView.clipsToBounds = YES;
  197. }
  198. return _contentView;
  199. }
  200. - (UIView *)vertLine{
  201. if (_vertLine == nil) {
  202. _vertLine = [[UIView alloc]init];
  203. _vertLine.backgroundColor = [UIColor whiteColor];
  204. }
  205. return _vertLine;
  206. }
  207. @end