YOUPAILCGiftSendView.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  1. //
  2. // YOUPAILCGiftSendView.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/29.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCGiftSendView.h"
  9. @interface YOUPAILCGiftSendView()
  10. @property(nonatomic,strong)YOUPAILCGiftModel* youpaipgiftModel;
  11. @property (nonatomic,strong)UIControl *youpaipbackControl;
  12. @property (nonatomic,strong)UIView *youpaipmenuView;
  13. @property (nonatomic,strong)UILabel* youpaipcenterL;
  14. @end
  15. @implementation YOUPAILCGiftSendView
  16. - (UIWindow*)youpaipalertWindow{
  17. if (!_youpaipalertWindow) {
  18. _youpaipalertWindow = [[UIWindow alloc]initWithFrame:[UIScreen mainScreen].bounds];
  19. _youpaipalertWindow.windowLevel = UIWindowLevelAlert+1;
  20. }
  21. return _youpaipalertWindow;
  22. }
  23. -(instancetype)initWithModel:(YOUPAILCGiftModel*)model type:(NSInteger)type{
  24. if (self = [super init]) {
  25. self.youpaiptype = type;
  26. self.youpaipgiftModel = model;
  27. [self youpaifsetupView];
  28. }
  29. return self;
  30. }
  31. - (void)youpaifsetupView{
  32. self.frame = [UIScreen mainScreen].bounds;
  33. UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
  34. [control addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
  35. control.backgroundColor = [UIColor clearColor];
  36. self.youpaipbackControl = control;
  37. [self addSubview:control];
  38. UIView* menuView = [[UIView alloc]initWithFrame:CGRectMake(32.0f, -KScreenHeight, KScreenWidth-64.0f, 271.0f)];
  39. menuView.backgroundColor = HexColorFromRGB(0x2A2935);
  40. menuView.layer.cornerRadius = 10.0f;
  41. menuView.layer.masksToBounds = YES;
  42. menuView.layer.borderColor = HexColorFromRGB(0x4F4B5B).CGColor;
  43. menuView.layer.borderWidth = 0.5f;
  44. self.youpaipmenuView = menuView;
  45. [self addSubview:menuView];
  46. UIButton* cancelBtn = [[UIButton alloc]initWithFrame:CGRectMake(0.0f, 0.0f, 43.0f, 43.0f)];
  47. [cancelBtn setImage:[UIImage imageNamed:@"vqu_images_H_home_gift_send_close"] forState:UIControlStateNormal];
  48. [cancelBtn setImage:[UIImage imageNamed:@"vqu_images_H_home_gift_send_close"] forState:UIControlStateHighlighted];
  49. [cancelBtn addTarget:self action:@selector(youpaifcancelBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  50. [menuView addSubview:cancelBtn];
  51. UIImageView* imgV = [[UIImageView alloc]initWithFrame:CGRectMake((menuView.mj_w - 85.0f) / 2.0f, 25.0f, 85.0f, 85.0f)];
  52. imgV.contentMode = UIViewContentModeScaleAspectFill;
  53. [menuView addSubview:imgV];
  54. UILabel* tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(30.0f, CGRectGetMaxY(imgV.frame) + 5.0f, menuView.mj_w - 60.0f, 14.0f)];
  55. tipLabel.textAlignment = NSTextAlignmentCenter;
  56. tipLabel.font = LCFont12;
  57. tipLabel.textColor = [UIColor whiteColor];
  58. [menuView addSubview:tipLabel];
  59. if (self.youpaiptype==1) {
  60. tipLabel.text = @"赠送玫瑰花";
  61. imgV.image = [UIImage imageNamed:@"vqu_images_D_dynamic_gift_send"];
  62. }else{
  63. tipLabel.text = [NSString stringWithFormat:@"赠送%@",self.youpaipgiftModel.youpaipname];
  64. imgV.image = [LCTools giftImgWithGiftUrlStr:self.youpaipgiftModel.youpaipimg];
  65. }
  66. UIView* countView = [[UIView alloc]initWithFrame:CGRectMake((menuView.mj_w - 105.0f) / 2.0f, CGRectGetMaxY(tipLabel.frame) + 10.0f, 105.0f, 28.0f)];
  67. countView.backgroundColor = HexColorFromRGB(0x4F4B5B);
  68. countView.layer.cornerRadius = 14.0f;
  69. countView.layer.masksToBounds = YES;
  70. [menuView addSubview:countView];
  71. UIButton* leftBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 40, 28.0f)];
  72. leftBtn.titleLabel.font = LCFont14;
  73. [leftBtn setTitle:@"-" forState:(UIControlStateNormal)];
  74. [leftBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  75. leftBtn.adjustsImageWhenHighlighted = NO;
  76. [leftBtn setEnlargeEdge:20];
  77. [leftBtn addTarget:self action:@selector(youpaifleftBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  78. [countView addSubview:leftBtn];
  79. UIButton* rightBtn = [[UIButton alloc]initWithFrame:CGRectMake(65.0f, 0, 40, 28.0f)];
  80. rightBtn.titleLabel.font = LCFont14;
  81. [rightBtn setTitle:@"+" forState:(UIControlStateNormal)];
  82. [rightBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  83. rightBtn.adjustsImageWhenHighlighted = NO;
  84. [rightBtn setEnlargeEdge:20];
  85. [rightBtn addTarget:self action:@selector(youpaifrightBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  86. [countView addSubview:rightBtn];
  87. UILabel* centerL = [[UILabel alloc]initWithFrame:CGRectMake(40, 0, 25.0f, 28.0f)];
  88. centerL.textAlignment = NSTextAlignmentCenter;
  89. centerL.textColor = [UIColor whiteColor];
  90. centerL.font = LCFont(14);
  91. centerL.text = @"1";
  92. [countView addSubview:centerL];
  93. self.youpaipcenterL = centerL;
  94. UIButton* confirmBtn = [[UIButton alloc]initWithFrame:CGRectMake(30.0f, CGRectGetMaxY(countView.frame) + 36.0f, menuView.mj_w - 60.0f, 48.0f)];
  95. confirmBtn.titleLabel.font = LCFont(17);
  96. confirmBtn.layer.cornerRadius = 24.0f;
  97. confirmBtn.clipsToBounds = YES;
  98. [confirmBtn setBackgroundImage:[LCTools ColorImage:confirmBtn.mj_size FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight] forState:UIControlStateNormal];
  99. [confirmBtn setTitle:@"确定" forState:(UIControlStateNormal)];
  100. [confirmBtn setTitleColor:[UIColor whiteColor] forState:(UIControlStateNormal)];
  101. confirmBtn.adjustsImageWhenHighlighted = NO;
  102. [confirmBtn addTarget:self action:@selector(youpaifconfirmBtnClick) forControlEvents:(UIControlEventTouchUpInside)];
  103. [menuView addSubview:confirmBtn];
  104. }
  105. - (void)youpaifleftBtnClick{
  106. if ([self.youpaipcenterL.text integerValue]>1) {
  107. self.youpaipcenterL.text = [NSString stringWithFormat:@"%zd",[self.youpaipcenterL.text integerValue]-1];
  108. }
  109. }
  110. - (void)youpaifrightBtnClick{
  111. if ([self.youpaipcenterL.text integerValue]<99) {
  112. self.youpaipcenterL.text = [NSString stringWithFormat:@"%zd",[self.youpaipcenterL.text integerValue]+1];
  113. }
  114. }
  115. - (void)youpaifcancelBtnClick{
  116. [self youpaifhide];
  117. }
  118. - (void)youpaifconfirmBtnClick{
  119. if (self.youpaipsendMultiGift) {
  120. [self youpaifhide];
  121. if (self.youpaiptype==1) {
  122. self.youpaipsendMultiGift(@"", [self.youpaipcenterL.text integerValue]);
  123. }else{
  124. self.youpaipsendMultiGift(self.youpaipgiftModel.youpaipid, [self.youpaipcenterL.text integerValue]);
  125. }
  126. }
  127. }
  128. - (void)youpaifshow{
  129. _youpaipalertWindow.hidden = NO;
  130. [_youpaipalertWindow addSubview:self];
  131. self.youpaipbackControl.backgroundColor = HexColorFromRGBA(0x000000, 0.3);
  132. [UIView animateWithDuration:0.25 animations:^{
  133. self.youpaipmenuView.frame = CGRectMake(32.0f, (KScreenHeight - 271.0f)/2, KScreenWidth-64.0f, 271.0f);
  134. } completion:^(BOOL finished) {
  135. }];
  136. }
  137. - (void)youpaifhide{
  138. self.youpaipbackControl.backgroundColor = [UIColor clearColor];
  139. [UIView animateWithDuration:0.25 animations:^{
  140. self.youpaipmenuView.frame = CGRectMake(32.0f, -KScreenHeight, KScreenWidth-64.0f, 271.0f);
  141. } completion:^(BOOL finished) {
  142. [self removeFromSuperview];
  143. _youpaipalertWindow.hidden = YES;
  144. _youpaipalertWindow = nil;
  145. }];
  146. }
  147. @end