YOUPAILZChatRoomWindow.m 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. //
  2. // YOUPAILZChatRoomWindow.m
  3. // VQU
  4. //
  5. // Created by CY on 2021/11/12.
  6. // Copyright © 2021 MS. All rights reserved.
  7. //
  8. #import "YOUPAILZChatRoomWindow.h"
  9. #import "LOTAnimationView.h"
  10. @interface YOUPAILZChatRoomWindow ()
  11. @property (nonatomic,weak)UIImageView *youpaipcoverImgV;
  12. @end
  13. @implementation YOUPAILZChatRoomWindow
  14. - (instancetype)init{
  15. if (self = [super init]) {
  16. [self youpaifinitUI];
  17. self.hidden = YES;
  18. }
  19. return self;
  20. }
  21. - (void)youpaifinitUI{
  22. UIImageView *youpaipcoverImgV = [[UIImageView alloc] init];
  23. youpaipcoverImgV.layer.cornerRadius = 32.0f;
  24. youpaipcoverImgV.clipsToBounds = YES;
  25. youpaipcoverImgV.contentMode = UIViewContentModeScaleAspectFill;
  26. [self addSubview:youpaipcoverImgV];
  27. self.youpaipcoverImgV = youpaipcoverImgV;
  28. [youpaipcoverImgV mas_makeConstraints:^(MASConstraintMaker *make) {
  29. make.center.equalTo(self);
  30. make.size.mas_offset(CGSizeMake(64.0f, 64.0f));
  31. }];
  32. LOTAnimationView *youpaiptalkingAnimationView = [LOTAnimationView animationWithFilePath:[[NSBundle mainBundle] pathForResource:@"ic_chatroom_seat_animation" ofType:@"json"]];
  33. youpaiptalkingAnimationView.frame = CGRectMake(0.0f, 0.0f, 64.0f * 1.7f, 64.0f * 1.7f);
  34. youpaiptalkingAnimationView.loopAnimation = YES;
  35. youpaiptalkingAnimationView.contentMode = UIViewContentModeScaleAspectFill;
  36. [youpaiptalkingAnimationView play];
  37. [self addSubview:youpaiptalkingAnimationView];
  38. [youpaiptalkingAnimationView mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.center.equalTo(youpaipcoverImgV);
  40. make.size.mas_offset(CGSizeMake(64.0f * 1.7f, 64.0f * 1.7f));
  41. }];
  42. // RippleAnimationView *youpaiptalkingAnimationView = [[RippleAnimationView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 54.0f, 54.0f) animationType:AnimationTypeWithoutBackground];
  43. // [self addSubview:youpaiptalkingAnimationView];
  44. // [youpaiptalkingAnimationView mas_makeConstraints:^(MASConstraintMaker *make) {
  45. // make.center.equalTo(youpaipcoverImgV);
  46. // make.size.mas_offset(CGSizeMake(54.0f, 54.0f));
  47. // }];
  48. UIButton *showBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  49. [showBtn addTarget:self action:@selector(youpaifshowBtnClick) forControlEvents:UIControlEventTouchUpInside];
  50. [self addSubview:showBtn];
  51. [showBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  52. make.right.top.left.bottom.offset(0.0f);
  53. }];
  54. UIButton *closeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  55. [closeBtn setImage:[UIImage imageNamed:@"vqu_images_chatroom_end"] forState:UIControlStateNormal];
  56. [closeBtn addTarget:self action:@selector(youpaifcloseBtnClick) forControlEvents:UIControlEventTouchUpInside];
  57. [self addSubview:closeBtn];
  58. [closeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.top.equalTo(youpaipcoverImgV.mas_top).offset(0.0f);
  60. make.right.equalTo(youpaipcoverImgV.mas_right).offset(0.0f);
  61. make.size.mas_offset(CGSizeMake(25.5f, 36.0f));
  62. }];
  63. UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifhandlePan:)];
  64. [self addGestureRecognizer:panGestureRecognizer];
  65. }
  66. - (void)youpaifhandlePan:(UIPanGestureRecognizer*) recognizer{
  67. CGPoint translation = [recognizer translationInView:self.superview];
  68. CGFloat centerX = recognizer.view.center.x+ translation.x;
  69. CGFloat thecenter = 0;
  70. recognizer.view.center = CGPointMake(centerX,recognizer.view.center.y+ translation.y);
  71. [recognizer setTranslation:CGPointZero inView:self.superview];
  72. if(recognizer.state == UIGestureRecognizerStateEnded || recognizer.state == UIGestureRecognizerStateCancelled) {
  73. if(centerX > KScreenWidth/2) {
  74. thecenter = KScreenWidth-self.mj_w/2 - 14.0f;
  75. }else{
  76. thecenter = self.mj_w / 2 + 14.0f;
  77. }
  78. [UIView animateWithDuration:0.25f animations:^{
  79. CGFloat y = recognizer.view.center.y;
  80. if (recognizer.view.center.y < NavBarHeight) {
  81. y = NavBarHeight + 27.0f + self.mj_w / 2.0f;
  82. }else if (recognizer.view.center.y > KScreenHeight - TabbarHeight - 27.0f - self.mj_w / 2.0f){
  83. y = KScreenHeight - TabbarHeight - 27.0f - self.mj_w / 2.0f;
  84. }
  85. recognizer.view.center=CGPointMake(thecenter, y + translation.y);
  86. }];
  87. }
  88. }
  89. - (void)setYoupaipchatroomModel:(YOUPAILZChatRoomModel *)youpaipchatroomModel{
  90. _youpaipchatroomModel = youpaipchatroomModel;
  91. [self.youpaipcoverImgV sd_setImageWithURL:[LCTools getImageUrlWithAddress:youpaipchatroomModel.youpaipcoverimg]];
  92. }
  93. - (void)youpaifcloseBtnClick{
  94. if (self.youpaipcloseBlock != nil) {
  95. self.hidden = YES;
  96. self.youpaipcloseBlock();
  97. }
  98. }
  99. - (void)youpaifshowBtnClick{
  100. if (self.showChatRoomBlock != nil) {
  101. self.hidden = YES;
  102. self.showChatRoomBlock();
  103. }
  104. }
  105. @end