123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- //
- // XYFloatingDragVoiceView.m
- // Starbuds
- //
- // Created by 翟玉磊 on 2020/6/29.
- // Copyright © 2020 翟玉磊. All rights reserved.
- // 语音聊天室悬浮view
- #import "XYFloatingDragVoiceView.h"
- #import "XYChatRoomInfoModel.h"
- @interface XYFloatingDragVoiceView ()
- @property (nonatomic, strong) UIImageView *bgImageView;
- @property (nonatomic, strong) UIImageView *contentImageView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *subtitleLabel;
- @property (nonatomic, strong) UIButton *closeButton;
- @end
- @implementation XYFloatingDragVoiceView
- #pragma mark - Public
- - (void)clear {
- [self stopAnimation];
- }
- - (void)setupViewDataWithModel:(XYChatRoomInfoModel *)model {
- [self.contentImageView sd_setImageWithURL:UrlForString(model.roomCover) placeholderImage:placeholderImage()];
- self.titleLabel.text = model.roomName;
- self.subtitleLabel.text = @"点击返回聊天室";
-
- [self startAnimation];
- }
- - (void)startAnimation {
- // 旋转动画
- CABasicAnimation *layer = [CABasicAnimation animationWithKeyPath:@"transform.rotation"];
- layer.toValue = @(2*M_PI);
- layer.duration = 5;
- layer.removedOnCompletion = false;
- layer.repeatCount = MAXFLOAT;
- [self.contentImageView.layer addAnimation:layer forKey:nil];
- }
- - (void)stopAnimation {
- if (self.contentImageView.layer) {
- [self.contentImageView.layer removeAllAnimations];
- }
- }
- #pragma mark - Action
- // 关闭悬浮窗
- - (void)closeButtonAction:(id)sender {
- if (self.closeFloatingDragBlock) {
- self.closeFloatingDragBlock();
- }
- }
- #pragma mark - 初始化
- - (instancetype)initWithFrame:(CGRect)frame {
-
- if (self = [super initWithFrame:frame]) {
-
- [self _setup];
- [self _setupSubViews];
- [self _makeSubViewsConstraint];
- }
- return self;
- }
- #pragma mark - 配置属性
- - (void)_setup {
- self.backgroundColor = Color_Clear;
- }
- #pragma mark - 设置子控件
- - (void)_setupSubViews {
- [self addSubview:self.bgImageView];
- [self addSubview:self.contentImageView];
- [self addSubview:self.titleLabel];
- [self addSubview:self.subtitleLabel];
- [self addSubview:self.closeButton];
- }
- #pragma mark - 布局子控件
- - (void)_makeSubViewsConstraint {
- [self.bgImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.edges.equalTo(self);
- }];
- [self.contentImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self).offset(4.0f);
- make.centerY.equalTo(self);
- make.width.height.equalTo(@40.0f);
- }];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentImageView.mas_right).offset(4.0f);
- make.top.equalTo(self.contentImageView).offset(3.0f);
- make.height.equalTo(@17.0f);
- }];
- [self.subtitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.contentImageView.mas_right).offset(4.0f);
- make.top.equalTo(self.titleLabel.mas_bottom);
- make.height.equalTo(@14.0f);
- }];
- [self.closeButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self).offset(4.0f);
- make.centerY.equalTo(self);
- make.width.height.equalTo(@40.0f);
- make.left.equalTo(self.titleLabel.mas_right).offset(5.0f);
- }];
-
- [self.contentImageView addViewBorder:Color_White redian:20];
-
- // 设置背景图
- self.bgImageView.image = [UIImage commonRedGradientColorImageWithImgSize:self.bounds.size];
- [self.bgImageView addViewBorder:Color_Clear redian:self.f_heigh/2];
- }
- #pragma mark - Getter/Setter
- - (UIImageView *)bgImageView {
- if (!_bgImageView) {
- _bgImageView = [UIImageView new];
- }
- return _bgImageView;
- }
- - (UIImageView *)contentImageView {
- if (!_contentImageView) {
- _contentImageView = [UIImageView new];
- _contentImageView.clipsToBounds = YES;
- _contentImageView.contentMode = UIViewContentModeScaleAspectFill;
- _contentImageView.image = placeholderImage();
- }
- return _contentImageView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [UILabel createLabelTextColor:Color_White fount:Font_B(12)];
- }
- return _titleLabel;
- }
- - (UILabel *)subtitleLabel {
- if (!_subtitleLabel) {
- _subtitleLabel = [UILabel createLabelTextColor:Color_White fount:Font(10)];
- }
- return _subtitleLabel;
- }
- - (UIButton *)closeButton {
- if (!_closeButton) {
- _closeButton = [UIButton buttonWithType:UIButtonTypeCustom];
- [_closeButton setImage:ImageNamed(@"xy-chatroom-room-close") forState:UIControlStateNormal];
- _closeButton.backgroundColor = Color_Clear;
- [_closeButton addTarget:self action:@selector(closeButtonAction:) forControlEvents:UIControlEventTouchUpInside];
- }
- return _closeButton;
- }
- @end
|