澎湃iPad上线版本

commentActionView.m 6.7KB

    // // commentActionView.m // ThePaperDemo // // Created by scar1900 on 14/12/30. // Copyright (c) 2014年 scar1900. All rights reserved. // #import "commentActionView.h" @interface TriangleView : UIView @end @implementation TriangleView - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; [self setNeedsDisplay]; } - (void)drawRect:(CGRect)rect { //设置背景颜色 [[UIColor clearColor]set]; UIRectFill([self bounds]); //拿到当前视图准备好的画板 CGContextRef context = UIGraphicsGetCurrentContext(); //利用path进行绘制三角形 CGContextBeginPath(context);//标记 CGContextMoveToPoint(context, 0, 0);//设置起点 CGContextAddLineToPoint(context, self.bounds.size.width, 0); CGContextAddLineToPoint(context, self.bounds.size.width/2, self.bounds.size.height); CGContextClosePath(context);//路径结束标志,不写默认封闭 [[UIColor colorWithHexString:@"0x261e1c"] setFill]; //设置填充色 // [[UIColor // whiteColor] setStroke]; //设置边框颜色 CGContextDrawPath(context, kCGPathFillStroke);//绘制路径path } @end @interface commentActionView() { void(^commentActionHandler)(commentObjectVO *commentBO,commentActionType type); } @property(nonatomic, strong)UIButton *replyBtn; @property(nonatomic, strong)UIButton *copyingBtn; @property(nonatomic, strong)UIButton *praisingBtn; @property(nonatomic, strong)TriangleView *bottomView; @end @implementation commentActionView @synthesize commentBO; @synthesize delegate; @synthesize isRotate; - (id)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { self.backgroundColor = [UIColor clearColor]; [self addSubview:self.replyBtn]; [self addSubview:self.copyingBtn]; [self addSubview:self.praisingBtn]; [self addSubview:self.bottomView]; self.isRotate = NO; } return self; } - (UIButton*)replyBtn { if (!_replyBtn) { _replyBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _replyBtn.clipsToBounds = YES; [_replyBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x261e1c"]) forState:UIControlStateNormal]; [_replyBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK]) forState:UIControlStateHighlighted]; [_replyBtn setTitle:@"回复" forState:UIControlStateNormal]; [_replyBtn addTarget:self action:@selector(replyAction:) forControlEvents:UIControlEventTouchUpInside]; _replyBtn.titleLabel.font = appFont(35/2, NO); } return _replyBtn; } - (UIButton*)copyingBtn { if (!_copyingBtn) { _copyingBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _copyingBtn.clipsToBounds = YES; [_copyingBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x261e1c"]) forState:UIControlStateNormal]; [_copyingBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK]) forState:UIControlStateHighlighted]; [_copyingBtn setTitle:@"复制" forState:UIControlStateNormal]; [_copyingBtn addTarget:self action:@selector(copyAction:) forControlEvents:UIControlEventTouchUpInside]; _copyingBtn.titleLabel.font = appFont(35/2, NO); } return _copyingBtn; } - (UIButton*)praisingBtn { if (!_praisingBtn) { _praisingBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _praisingBtn.clipsToBounds = YES; [_praisingBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:@"0x261e1c"]) forState:UIControlStateNormal]; [_praisingBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BUTTONSELECTBACK]) forState:UIControlStateHighlighted]; [_praisingBtn setTitle:@"点赞" forState:UIControlStateNormal]; [_praisingBtn addTarget:self action:@selector(praiseAction:) forControlEvents:UIControlEventTouchUpInside]; _praisingBtn.titleLabel.font = appFont(35/2, NO); } return _praisingBtn; } - (TriangleView*)bottomView { if (!_bottomView) { _bottomView = [[TriangleView alloc]initWithFrame:CGRectZero]; } return _bottomView; } - (void)replyAction:(UIButton*)btn { if (commentActionHandler) { commentActionHandler(self.commentBO,replying); } } - (void)copyAction:(UIButton*)btn { } - (void)praiseAction:(UIButton*)btn { } - (void)layoutSubviews { [super layoutSubviews]; if (!isRotate) { self.bottomView.transform = CGAffineTransformMakeRotation(0); self.replyBtn.frame = CGRectMake(0, 0, 120/2-1, 30); self.copyingBtn.frame = CGRectMake(CGRectGetMaxX(self.replyBtn.frame)+1, 0, 120/2-1, 30); self.praisingBtn.frame = CGRectMake(CGRectGetWidth(self.bounds)-120/2, 0, 120/2, 30); self.bottomView.frame = CGRectMake(CGRectGetWidth(self.bounds)/2-15/2, CGRectGetMaxY(self.replyBtn.frame), 15, 10); }else { self.bottomView.frame = CGRectMake(CGRectGetWidth(self.bounds)/2-15/2, 0, 15, 10); self.bottomView.transform = CGAffineTransformMakeRotation(M_PI); self.replyBtn.frame = CGRectMake(0, CGRectGetMaxY(self.bottomView.frame), 120/2-1, 30); self.copyingBtn.frame = CGRectMake(CGRectGetMaxX(self.replyBtn.frame)+1, CGRectGetMaxY(self.bottomView.frame), 120/2-1, 30); self.praisingBtn.frame = CGRectMake(CGRectGetWidth(self.bounds)-120/2, CGRectGetMaxY(self.bottomView.frame), 120/2, 30); } UIBezierPath *maskPath1 = [UIBezierPath bezierPathWithRoundedRect:self.replyBtn.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(2, 2)]; CAShapeLayer *maskLayer1 = [[CAShapeLayer alloc] init]; maskLayer1.frame = self.replyBtn.bounds; maskLayer1.path = maskPath1.CGPath; self.replyBtn.layer.mask = maskLayer1; UIBezierPath *maskPath2 = [UIBezierPath bezierPathWithRoundedRect:self.replyBtn.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(2, 2)]; CAShapeLayer *maskLayer2 = [[CAShapeLayer alloc] init]; maskLayer2.frame = self.replyBtn.bounds; maskLayer2.path = maskPath2.CGPath; self.praisingBtn.layer.mask = maskLayer2; } - (void)dismissCommentContent { [self setHidden:YES]; [CoreAnimationEffect animationEaseOut:self]; [self removeFromSuperview]; } - (void)commentActionHandler:(void (^)(commentObjectVO *,commentActionType))block { commentActionHandler = [block copy]; } @end