YBInvitationView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. //
  2. // YBInvitationView.m
  3. // YBVideo
  4. //
  5. // Created by YB007 on 2019/12/9.
  6. // Copyright © 2019 cat. All rights reserved.
  7. //
  8. #import "YBInvitationView.h"
  9. @implementation YBInvitationView{
  10. UIView *showView;
  11. UITextField *codeTextF;
  12. }
  13. -(instancetype)initWithType:(BOOL)isForce{
  14. if (self = [super init]) {
  15. self.frame = CGRectMake(0, 0, _window_width, _window_height);
  16. self.backgroundColor = [[UIColor blackColor] colorWithAlphaComponent:0.3];
  17. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(keyboardHide)];
  18. [self addGestureRecognizer:tap];
  19. [self creatUI:isForce];
  20. }
  21. return self;
  22. }
  23. - (void)keyboardHide{
  24. [codeTextF resignFirstResponder];
  25. }
  26. - (void)showviewClick{
  27. }
  28. - (void)creatUI:(BOOL)isForce{
  29. showView = [[UIView alloc]initWithFrame:CGRectMake(_window_width*0.22, _window_height, _window_width*0.56, _window_width*0.56*0.76)];
  30. showView.backgroundColor = [UIColor whiteColor];
  31. showView.layer.cornerRadius = 10;
  32. showView.layer.masksToBounds = YES;
  33. showView.clipsToBounds = YES;
  34. [self addSubview:showView];
  35. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(showviewClick)];
  36. [showView addGestureRecognizer:tap];
  37. UIImageView *headerImgV = [[UIImageView alloc]init];
  38. headerImgV.userInteractionEnabled = YES;
  39. headerImgV.image = [UIImage imageNamed:@"邀请码背景"];
  40. [showView addSubview:headerImgV];
  41. [headerImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.left.right.equalTo(showView);
  43. make.height.equalTo(showView).multipliedBy(0.28125);
  44. }];
  45. UILabel *label = [[UILabel alloc]init];
  46. label.font = SYS_Font(15);
  47. label.textColor = [UIColor whiteColor];
  48. label.text = YZMsg(@"输入邀请码");
  49. [headerImgV addSubview:label];
  50. [label mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.centerX.equalTo(headerImgV);
  52. make.centerY.equalTo(headerImgV).multipliedBy(1.1);
  53. }];
  54. if (!isForce) {
  55. UIButton *closeBtn = [UIButton buttonWithType:0];
  56. [closeBtn setImage:[UIImage imageNamed:@"邀请码关闭"] forState:0];
  57. [closeBtn addTarget:self action:@selector(hideSelf) forControlEvents:UIControlEventTouchUpInside];
  58. closeBtn.imageEdgeInsets = UIEdgeInsetsMake(10, 10, 10, 10);
  59. [headerImgV addSubview:closeBtn];
  60. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  61. make.right.top.equalTo(showView);
  62. make.width.height.mas_equalTo(30);
  63. }];
  64. }
  65. codeTextF = [[UITextField alloc]init];
  66. codeTextF.textColor = RGB_COLOR(@"#323232", 1);
  67. codeTextF.font = [UIFont boldSystemFontOfSize:20];
  68. codeTextF.layer.cornerRadius = 3;
  69. codeTextF.layer.masksToBounds = YES;
  70. codeTextF.layer.borderColor = RGB_COLOR(@"#e5e5e5", 1).CGColor;
  71. codeTextF.layer.borderWidth = 1;
  72. codeTextF.leftViewMode = UITextFieldViewModeAlways;
  73. UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 10, 40)];
  74. codeTextF.leftView = view;
  75. [showView addSubview:codeTextF];
  76. [codeTextF mas_makeConstraints:^(MASConstraintMaker *make) {
  77. make.width.equalTo(showView).multipliedBy(0.85);
  78. make.centerX.equalTo(showView);
  79. make.height.equalTo(showView).multipliedBy(0.25);
  80. make.centerY.equalTo(showView).multipliedBy(1.025);
  81. }];
  82. UIButton *sureBtn = [UIButton buttonWithType:0];
  83. [sureBtn setTitle:YZMsg(@"确定") forState:0];
  84. [sureBtn setTitleColor:RGB_COLOR(@"#7200FF", 1) forState:0];//#7200FF//7014e2
  85. sureBtn.titleLabel.font = SYS_Font(15);
  86. [sureBtn addTarget:self action:@selector(submitInvitationCode) forControlEvents:UIControlEventTouchUpInside];
  87. [showView addSubview:sureBtn];
  88. [sureBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  89. make.right.left.bottom.equalTo(showView);
  90. make.height.equalTo(showView).multipliedBy(0.25);
  91. }];
  92. [UIView animateWithDuration:0.3 animations:^{
  93. showView.centerY = self.centerY * 0.7;
  94. }completion:^(BOOL finished) {
  95. //[codeTextF becomeFirstResponder];
  96. }];
  97. }
  98. - (void)hideSelf{
  99. [self keyboardHide];
  100. [UIView animateWithDuration:0.3 animations:^{
  101. showView.y = _window_height;
  102. }completion:^(BOOL finished) {
  103. [self removeFromSuperview];
  104. }];
  105. }
  106. - (void)submitInvitationCode{
  107. if (codeTextF.text == nil || codeTextF.text == NULL || codeTextF.text.length == 0) {
  108. [MBProgressHUD showError:YZMsg(@"邀请码不能为空")];
  109. return;
  110. }
  111. [YBNetworking postWithUrl:@"Agent.setAgent" Dic:@{@"agentcode":codeTextF.text} Suc:^(int code, id info, NSString *msg) {
  112. if (code == 0) {
  113. [self hideSelf];
  114. }
  115. [MBProgressHUD showPop:msg];
  116. } Fail:^(id fail) {
  117. }];
  118. }
  119. @end