XYFloatingDragVoiceView.m 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. //
  2. // XYFloatingDragVoiceView.m
  3. // Starbuds
  4. //
  5. // Created by 翟玉磊 on 2020/6/29.
  6. // Copyright © 2020 翟玉磊. All rights reserved.
  7. // 语音聊天室悬浮view
  8. #import "XYFloatingDragVoiceView.h"
  9. #import "XYChatRoomInfoModel.h"
  10. @interface XYFloatingDragVoiceView ()
  11. @property (nonatomic, strong) UIImageView *bgImageView;
  12. @property (nonatomic, strong) UIImageView *contentImageView;
  13. @property (nonatomic, strong) UILabel *titleLabel;
  14. @property (nonatomic, strong) UILabel *subtitleLabel;
  15. @property (nonatomic, strong) UIButton *closeButton;
  16. @end
  17. @implementation XYFloatingDragVoiceView
  18. #pragma mark - Public
  19. - (void)clear {
  20. [self stopAnimation];
  21. }
  22. - (void)setupViewDataWithModel:(XYChatRoomInfoModel *)model {
  23. [self.contentImageView sd_setImageWithURL:UrlForString(model.roomCover) placeholderImage:placeholderImage()];
  24. self.titleLabel.text = model.roomName;
  25. self.subtitleLabel.text = @"点击返回聊天室";
  26. [self startAnimation];
  27. }
  28. - (void)startAnimation {
  29. // 旋转动画
  30. CABasicAnimation *layer = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
  31. layer.toValue = @(2*M_PI);
  32. layer.duration = 5;
  33. layer.removedOnCompletion = false;
  34. layer.repeatCount = MAXFLOAT;
  35. [self.contentImageView.layer addAnimation:layer forKey:nil];
  36. }
  37. - (void)stopAnimation {
  38. if (self.contentImageView.layer) {
  39. [self.contentImageView.layer removeAllAnimations];
  40. }
  41. }
  42. #pragma mark - Action
  43. // 关闭悬浮窗
  44. - (void)closeButtonAction:(id)sender {
  45. if (self.closeFloatingDragBlock) {
  46. self.closeFloatingDragBlock();
  47. }
  48. }
  49. #pragma mark - 初始化
  50. - (instancetype)initWithFrame:(CGRect)frame {
  51. if (self = [super initWithFrame:frame]) {
  52. [self _setup];
  53. [self _setupSubViews];
  54. [self _makeSubViewsConstraint];
  55. }
  56. return self;
  57. }
  58. #pragma mark - 配置属性
  59. - (void)_setup {
  60. self.backgroundColor = Color_Clear;
  61. }
  62. #pragma mark - 设置子控件
  63. - (void)_setupSubViews {
  64. [self addSubview:self.bgImageView];
  65. [self addSubview:self.contentImageView];
  66. [self addSubview:self.titleLabel];
  67. [self addSubview:self.subtitleLabel];
  68. [self addSubview:self.closeButton];
  69. }
  70. #pragma mark - 布局子控件
  71. - (void)_makeSubViewsConstraint {
  72. [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  73. make.edges.equalTo(self);
  74. }];
  75. [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  76. make.left.equalTo(self).offset(4.0f);
  77. make.centerY.equalTo(self);
  78. make.width.height.equalTo(@40.0f);
  79. }];
  80. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  81. make.left.equalTo(self.contentImageView.mas_right).offset(4.0f);
  82. make.top.equalTo(self.contentImageView).offset(3.0f);
  83. make.height.equalTo(@17.0f);
  84. }];
  85. [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  86. make.left.equalTo(self.contentImageView.mas_right).offset(4.0f);
  87. make.top.equalTo(self.titleLabel.mas_bottom);
  88. make.height.equalTo(@14.0f);
  89. }];
  90. [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
  91. make.right.equalTo(self).offset(4.0f);
  92. make.centerY.equalTo(self);
  93. make.width.height.equalTo(@40.0f);
  94. make.left.equalTo(self.titleLabel.mas_right).offset(5.0f);
  95. }];
  96. [self.contentImageView addViewBorder:Color_White redian:20];
  97. // 设置背景图
  98. self.bgImageView.image = [UIImage commonRedGradientColorImageWithImgSize:self.bounds.size];
  99. [self.bgImageView addViewBorder:Color_Clear redian:self.f_heigh/2];
  100. }
  101. #pragma mark - Getter/Setter
  102. - (UIImageView *)bgImageView {
  103. if (!_bgImageView) {
  104. _bgImageView = [UIImageView new];
  105. }
  106. return _bgImageView;
  107. }
  108. - (UIImageView *)contentImageView {
  109. if (!_contentImageView) {
  110. _contentImageView = [UIImageView new];
  111. _contentImageView.clipsToBounds = YES;
  112. _contentImageView.contentMode = UIViewContentModeScaleAspectFill;
  113. _contentImageView.image = placeholderImage();
  114. }
  115. return _contentImageView;
  116. }
  117. - (UILabel *)titleLabel {
  118. if (!_titleLabel) {
  119. _titleLabel = [UILabel createLabelTextColor:Color_White fount:Font_B(12)];
  120. }
  121. return _titleLabel;
  122. }
  123. - (UILabel *)subtitleLabel {
  124. if (!_subtitleLabel) {
  125. _subtitleLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
  126. }
  127. return _subtitleLabel;
  128. }
  129. - (UIButton *)closeButton {
  130. if (!_closeButton) {
  131. _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
  132. [_closeButton setImage:ImageNamed(@"xy-chatroom-room-close") forState:UIControlStateNormal];
  133. _closeButton.backgroundColor = Color_Clear;
  134. [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
  135. }
  136. return _closeButton;
  137. }
  138. @end