200 lines
8.8 KiB
Objective-C
200 lines
8.8 KiB
Objective-C
//
|
|
// QXHeadlineView.m
|
|
// QXLive
|
|
//
|
|
// Created by 启星 on 2025/6/25.
|
|
//
|
|
|
|
#import "QXHeadlineView.h"
|
|
#import "QXUserHomePageViewController.h"
|
|
|
|
@interface QXHeadlineView()
|
|
|
|
@property (nonatomic,strong)UIButton *iconBtn;
|
|
|
|
@property (nonatomic,strong)UIView *headLineBgView;
|
|
@property (nonatomic,strong)UIImageView *bgImageView;
|
|
@property (nonatomic,strong)UIImageView *headImageView;
|
|
@property (nonatomic,strong)UIButton *headBtn;
|
|
@property (nonatomic,strong)UILabel *nameLabel;
|
|
@property (nonatomic,strong)UILabel *contentLabel;
|
|
|
|
@property (nonatomic,strong)UIButton *getBtn;
|
|
@property (nonatomic,strong)UIButton *trampleBtn;
|
|
@property (nonatomic,strong)UIButton *closeBtn;
|
|
@property (nonatomic,assign)BOOL isSmall;
|
|
@end
|
|
|
|
@implementation QXHeadlineView
|
|
|
|
- (instancetype)init
|
|
{
|
|
self = [super init];
|
|
if (self) {
|
|
self.frame = CGRectMake(12, SCREEN_HEIGHT-460, ScaleWidth(344), 64);
|
|
[self initSubviews];
|
|
}
|
|
return self;
|
|
}
|
|
|
|
-(void)initSubviews{
|
|
self.clipsToBounds = YES;
|
|
// [self addRoundedCornersWithRadius:8];
|
|
UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handlePan:)];
|
|
[self addGestureRecognizer:panRecognizer];
|
|
self.iconBtn = [[UIButton alloc] init];
|
|
self.iconBtn.frame = CGRectMake(0, 0, 78, 64);
|
|
// self.iconImageView.contentMode = UIViewContentModeScaleToFill;
|
|
[self.iconBtn setBackgroundImage:[UIImage imageNamed:@"room_headline_icon"] forState:(UIControlStateNormal)];
|
|
[self.iconBtn setBackgroundImage:[UIImage imageNamed:@"room_headline_icon"] forState:(UIControlStateHighlighted)];
|
|
[self.iconBtn addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self addSubview:self.iconBtn];
|
|
|
|
self.headLineBgView = [[UIView alloc] initWithFrame:CGRectMake(self.iconBtn.right-6, self.height-44, self.width-self.iconBtn.right-6, 44)];
|
|
self.headLineBgView.clipsToBounds = YES;
|
|
[self.headLineBgView addRoundedCornersWithRadius:4 byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomRight)];
|
|
[self insertSubview:self.headLineBgView belowSubview:self.iconBtn];
|
|
|
|
self.bgImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"room_headline_bg"]];
|
|
self.bgImageView.frame = self.headLineBgView.bounds;
|
|
self.bgImageView.contentMode = UIViewContentModeScaleToFill;
|
|
self.bgImageView.clipsToBounds = YES;
|
|
[self.headLineBgView addSubview:self.bgImageView];
|
|
|
|
|
|
|
|
self.headImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
|
self.headImageView.contentMode = UIViewContentModeScaleAspectFill;
|
|
self.headImageView.frame = CGRectMake(12, 9, ScaleWidth(28), ScaleWidth(28));
|
|
[self.headImageView addRoundedCornersWithRadius:ScaleWidth(14)];
|
|
self.headImageView.centerY = self.bgImageView.centerY;
|
|
self.headImageView.layer.borderWidth = 1;
|
|
self.headImageView.layer.borderColor = RGB16(0xffffff).CGColor;
|
|
[self.headLineBgView addSubview:self.headImageView];
|
|
|
|
self.headBtn = [[UIButton alloc] initWithFrame:CGRectMake(12, 0, 44, 44)];
|
|
[self.headBtn addTarget:self action:@selector(headerAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.headLineBgView addSubview:self.headBtn];
|
|
|
|
self.nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headImageView.right+4, self.headImageView.top-4, self.width-self.headImageView.right-4-60, 18)];
|
|
self.nameLabel.font = [UIFont boldSystemFontOfSize:12];
|
|
self.nameLabel.textColor = RGB16(0xffffff);
|
|
[self.headLineBgView addSubview:self.nameLabel];
|
|
|
|
self.contentLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.headImageView.right+4, self.nameLabel.bottom, self.width-self.headImageView.right-4-60, 18)];
|
|
self.contentLabel.font = [UIFont systemFontOfSize:12];
|
|
self.contentLabel.textColor = RGB16(0xffffff);
|
|
[self.headLineBgView addSubview:self.contentLabel];
|
|
|
|
|
|
|
|
self.closeBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.headLineBgView.width-22, 0, 22, 44)];
|
|
// self.closeBtn.backgroundColor = RGB16(0x9C7DED);
|
|
[self.closeBtn addRoundedCornersWithRadius:4 byRoundingCorners:(UIRectCornerTopRight|UIRectCornerBottomRight)];
|
|
[self.closeBtn setImage:[UIImage imageNamed:@"head_line_back"] forState:(UIControlStateNormal)];
|
|
[self.closeBtn addTarget:self action:@selector(backAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.headLineBgView addSubview:self.closeBtn];
|
|
|
|
self.getBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.closeBtn.left-2-ScaleWidth(22),12 , ScaleWidth(22), ScaleWidth(22))];
|
|
[self.getBtn addRoundedCornersWithRadius:ScaleWidth(11)];
|
|
self.getBtn.layer.borderWidth = 1;
|
|
self.getBtn.layer.borderColor = RGB16(0xffffff).CGColor;
|
|
[self.getBtn setTitle:@"抢" forState:(UIControlStateNormal)];
|
|
self.getBtn.titleLabel.font = [UIFont boldSystemFontOfSize:ScaleWidth(12)];
|
|
[self.getBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|
[self.getBtn addTarget:self action:@selector(getAction:) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.headLineBgView addSubview:self.getBtn];
|
|
self.getBtn.centerY = self.headImageView.centerY;
|
|
|
|
self.trampleBtn = [[UIButton alloc] initWithFrame:CGRectMake(self.getBtn.left-8-ScaleWidth(22),12 , ScaleWidth(22), ScaleWidth(22))];
|
|
[self.trampleBtn addRoundedCornersWithRadius:ScaleWidth(11)];
|
|
self.trampleBtn.layer.borderWidth = 1;
|
|
self.trampleBtn.layer.borderColor = RGB16(0xffffff).CGColor;
|
|
[self.trampleBtn setTitle:@"踩" forState:(UIControlStateNormal)];
|
|
self.trampleBtn.titleLabel.font = [UIFont boldSystemFontOfSize:ScaleWidth(12)];
|
|
[self.trampleBtn setTitleColor:RGB16(0xffffff) forState:(UIControlStateNormal)];
|
|
[self.trampleBtn addTarget:self action:@selector(trampleAction) forControlEvents:(UIControlEventTouchUpInside)];
|
|
[self.headLineBgView addSubview:self.trampleBtn];
|
|
self.trampleBtn.centerY = self.headImageView.centerY;
|
|
}
|
|
|
|
|
|
-(void)getAction:(UIButton*)sender{
|
|
if (self.getHeadlineBlock) {
|
|
self.getHeadlineBlock();
|
|
}
|
|
}
|
|
|
|
-(void)trampleAction{
|
|
[[QXGlobal shareGlobal] joinRoomWithRoomId:self.model.room_id isRejoin:NO navagationController:self.viewController.navigationController];
|
|
}
|
|
-(void)headerAction{
|
|
QXUserHomePageViewController *vc = [[QXUserHomePageViewController alloc] init];
|
|
vc.user_id = self.model.user_id;
|
|
vc.hidesBottomBarWhenPushed = YES;
|
|
[self.viewController.navigationController pushViewController:vc animated:YES];
|
|
}
|
|
|
|
-(void)backAction{
|
|
if (self.isSmall) {
|
|
[UIView animateWithDuration:0.15 animations:^{
|
|
// self.headLineBgView.width = self.width-self.iconImageView.right-6;
|
|
// self.closeBtn.left = self.headLineBgView.width-22;
|
|
// self.closeBtn.imageView.transform = CGAffineTransformIdentity;
|
|
|
|
self.width = ScaleWidth(344);
|
|
} completion:^(BOOL finished) {
|
|
self.isSmall = NO;
|
|
}];
|
|
}else{
|
|
|
|
[UIView animateWithDuration:0.15 animations:^{
|
|
// self.headLineBgView.width = 6+22;
|
|
// self.closeBtn.left = 6;
|
|
// self.closeBtn.imageView.transform = CGAffineTransformMakeRotation(180 * M_PI/180.0);
|
|
|
|
self.width = 78;
|
|
} completion:^(BOOL finished) {
|
|
self.isSmall = YES;
|
|
}];
|
|
}
|
|
|
|
}
|
|
|
|
-(void)setModel:(QXHeadLineModel *)model{
|
|
_model = model;
|
|
self.nameLabel.text = model.nickname;
|
|
[self.headImageView sd_setImageWithURL:[NSURL URLWithString:model.avatar] placeholderImage:[UIImage imageNamed:@"user_header_placehoulder"]];
|
|
self.contentLabel.text = model.content;
|
|
if (self.isSmall) {
|
|
[UIView animateWithDuration:0.15 animations:^{
|
|
// self.headLineBgView.width = self.width-self.iconImageView.right-6;
|
|
// self.closeBtn.left = self.headLineBgView.width-22;
|
|
// self.closeBtn.imageView.transform = CGAffineTransformIdentity;
|
|
|
|
self.width = ScaleWidth(344);
|
|
} completion:^(BOOL finished) {
|
|
self.isSmall = NO;
|
|
}];
|
|
}
|
|
}
|
|
|
|
|
|
-(void)handlePan:(UIPanGestureRecognizer*)recognizer{
|
|
if (recognizer.state == UIGestureRecognizerStateEnded) {
|
|
NSLog(@"拖动结束");
|
|
}
|
|
CGPoint translation = [recognizer translationInView:self.viewController.view];
|
|
// CGPoint panCenter = CGPointMake(recognizer.view.center.x + translation.x,
|
|
// recognizer.view.center.y + translation.y);
|
|
// if (panCenter.x-214/2 <= 0 || panCenter.x+214/2 >= SCREEN_WIDTH || panCenter.y < kSafeAreaTop || panCenter.y> SCREEN_HEIGHT-kSafeAreaBottom) {
|
|
// return;
|
|
// }
|
|
|
|
|
|
recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x,
|
|
recognizer.view.center.y + translation.y);
|
|
[recognizer setTranslation:CGPointZero inView:self.viewController.view];
|
|
}
|
|
@end
|