澎湃iPad上线版本

hotAnswerDetailController.m 11KB

    // // hotAnswerDetailController.m // ThePaperHD // // Created by scar1900 on 15/3/18. // Copyright (c) 2015年 scar1900. All rights reserved. // #import "hotAnswerDetailController.h" #import "TPSelectButton.h" @interface hotAnswerDetailController () @property(nonatomic, strong)UIButton *closeBtn; @property(nonatomic, strong)UIView *backView; @property(nonatomic, strong)UIImageView *backImgView; @property(nonatomic, strong)UILabel *contentNameLabel; @property(nonatomic, strong)UIView *contentLineView; @property(nonatomic, strong)UILabel *askContentLabel; @property(nonatomic, strong)UITextView *answerContentView; @property(nonatomic, strong)UIView *lineView; @property(nonatomic, strong)TPSelectButton *praiseButton; @property(nonatomic, strong)UIButton *headButton; @property(nonatomic, strong)UIButton *askBtn; @end @implementation hotAnswerDetailController @synthesize commentBO = _commentBO; @synthesize contentNameHeight; @synthesize askHeight; @synthesize answerHeight; @synthesize delegate; @synthesize backColor; - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. self.view.backgroundColor = [UIColor clearColor]; [self.view addSubview:self.closeBtn]; [self.view addSubview:self.backView]; [self.backView addSubview:self.backImgView]; [self.backView addSubview:self.contentNameLabel]; [self.backView addSubview:self.contentLineView]; [self.backView addSubview:self.askContentLabel]; [self.backView addSubview:self.answerContentView]; [self.backView addSubview:self.lineView]; [self.backView addSubview:self.praiseButton]; [self.backView addSubview:self.headButton]; [self.backView addSubview:self.askBtn]; } - (void)viewWillLayoutSubviews { [super viewWillLayoutSubviews]; self.closeBtn.frame = CGRectMake(0, 0, 50, 80); [self.closeBtn setImageEdgeInsets:UIEdgeInsetsMake(15, 0, 15, 0)]; self.backView.frame = CGRectMake(0, CGRectGetMaxY(self.closeBtn.frame), CGRectGetWidth(self.view.bounds), CGRectGetHeight(self.view.bounds)-CGRectGetHeight(self.closeBtn.frame)); self.backImgView.frame = self.backView.bounds; self.contentNameLabel.frame = CGRectMake(25, 8, 850/2, contentNameHeight); self.contentLineView.frame = CGRectMake(0, CGRectGetMaxY(self.contentNameLabel.frame)+8, CGRectGetWidth(self.backView.bounds), 1); self.askContentLabel.frame = CGRectMake(25, CGRectGetMaxY(self.contentLineView.frame)+15, 850/2, askHeight); self.answerContentView.frame = CGRectMake(190/2, CGRectGetMaxY(self.askContentLabel.frame)+25, 350, answerHeight); self.lineView.frame = CGRectMake(80, CGRectGetMinY(self.answerContentView.frame), 1, CGRectGetHeight(self.backView.bounds)-CGRectGetMinY(self.answerContentView.frame)); self.praiseButton.frame = CGRectMake(40-15, CGRectGetMinY(self.lineView.frame), 30, 86/2); self.headButton.frame = CGRectMake(0, 0, CGRectGetWidth(self.backView.bounds), 16+contentNameHeight); self.askBtn.frame = self.askContentLabel.frame; } - (UIView*)lineView { if (!_lineView) { _lineView = [[UIView alloc]initWithFrame:CGRectZero]; _lineView.backgroundColor = [UIColor whiteColor]; _lineView.alpha = 0.8; } return _lineView; } - (UIView*)contentLineView { if (!_contentLineView) { _contentLineView = [[UIView alloc]initWithFrame:CGRectZero]; _contentLineView.backgroundColor = [UIColor whiteColor]; _contentLineView.alpha = 0.8; } return _contentLineView; } - (UIView*)backView { if (!_backView){ _backView = [[UIView alloc]initWithFrame:CGRectZero]; _backView.backgroundColor = backColor; } return _backView; } - (UIImageView*)backImgView { if (!_backImgView) { _backImgView = [[UIImageView alloc]initWithFrame:CGRectZero]; _backImgView.image = Image(@"frontPage/hotAskBack.png"); } return _backImgView; } - (UIButton*)closeBtn { if (!_closeBtn) { _closeBtn = [UIButton buttonWithType:UIButtonTypeCustom]; [_closeBtn setImage:Image(@"login/popUpCloseBtn.png") forState:UIControlStateNormal]; [_closeBtn setImage:Image(@"login/popUpCloseBtn_s.png") forState:UIControlStateHighlighted]; [_closeBtn addTarget:self action:@selector(closeEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _closeBtn; } - (UILabel*)contentNameLabel { if (!_contentNameLabel) { _contentNameLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _contentNameLabel.textColor = [UIColor whiteColor]; _contentNameLabel.lineBreakMode = NSLineBreakByWordWrapping; _contentNameLabel.numberOfLines = 0; _contentNameLabel.textAlignment = NSTextAlignmentLeft; _contentNameLabel.font = appFont(11, NO); _contentNameLabel.backgroundColor = [UIColor clearColor]; } return _contentNameLabel; } - (UILabel*)askContentLabel { if (!_askContentLabel) { _askContentLabel = [[UILabel alloc]initWithFrame:CGRectZero]; _askContentLabel.textColor = [UIColor whiteColor]; _askContentLabel.textAlignment = NSTextAlignmentLeft; _askContentLabel.lineBreakMode = NSLineBreakByWordWrapping; _askContentLabel.numberOfLines = 0; _askContentLabel.font = appFont(20, YES); _askContentLabel.backgroundColor = [UIColor clearColor]; } return _askContentLabel; } - (UITextView*)answerContentView { if (!_answerContentView) { _answerContentView = [[UITextView alloc]initWithFrame:CGRectZero]; _answerContentView.textColor = [UIColor whiteColor]; _answerContentView.textAlignment = NSTextAlignmentLeft; _answerContentView.font = appFont(14, NO); _answerContentView.editable = NO; _answerContentView.backgroundColor = [UIColor clearColor]; } return _answerContentView; } - (TPSelectButton*)praiseButton { if (!_praiseButton) { _praiseButton = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(praiseHandler:)]; [_praiseButton setBUttonNormalImage:Image(@"frontPage/hotAnswerDetailPraise.png") highLightImage:Image(@"frontPage/hotAnswerDetailPraise_s.png") selectedImage:Image(@"frontPage/hotAnswerDetailPraise_s.png")]; _praiseButton.textLabel.font = appFont(15, NO); _praiseButton.textLabel.textColor = [UIColor whiteColor]; } return _praiseButton; } - (UIButton*)headButton { if (!_headButton) { _headButton = [UIButton buttonWithType:UIButtonTypeCustom]; _headButton.backgroundColor = [UIColor clearColor]; [_headButton addTarget:self action:@selector(headClick:) forControlEvents:UIControlEventTouchUpInside]; } return _headButton; } - (UIButton*)askBtn { if (!_askBtn) { _askBtn = [UIButton buttonWithType:UIButtonTypeCustom]; _askBtn.backgroundColor = [UIColor clearColor]; [_askBtn addTarget:self action:@selector(askBtnEvent:) forControlEvents:UIControlEventTouchUpInside]; } return _askBtn; } - (void)setCommentBO:(commentObjectVO *)data { _commentBO = data; self.contentNameLabel.text = data.contName; self.askContentLabel.text = data.content; NSDictionary *answerDic = data.answerList[0]; commentObjectVO *answerBO = setJsonDicToDataModel(answerDic, [commentObjectVO class]); self.answerContentView.text = answerBO.content; NSString *praiseNum = answerBO.praiseTimes; if (!isBlankString(praiseNum)) { self.praiseButton.titleText = praiseNum; } if (answerBO.isPraised && [answerBO.isPraised intValue] == 1) { [self.praiseButton setSelect:YES animation:NO]; }else { [self.praiseButton setSelect:NO animation:NO]; } } - (void)praiseHandler:(UIButton*)btn { if (btn.selected) { return; } [self.praiseButton setSelected:YES animated:YES];//【需求】点赞动画(bug:4969) NSDictionary *answerDic = self.commentBO.answerList[0]; commentObjectVO *answerBO = setJsonDicToDataModel(answerDic, [commentObjectVO class]); NSDictionary *dic = @{@"commentId":answerBO.commentId}; __weak typeof(self) Self = self; [Remote doJsonActionWithBlock:2000 requestUrl:commentPraiseURL parameter:dic withWaitCursor:NO completion:^(BOOL success, NSString *message, id responseData) { if (success) { NSString *praseNumStr = responseData[@"praiseTimes"]; if([praseNumStr intValue] <1000){//点赞:点赞超过1K的,几个页面会出现显示不全的现象(bug:5371) Self.praiseButton.textLabel.text = praseNumStr; } // Self.praiseButton.textLabel.text = praseNumStr; TPLOG(@"点赞成功"); //点赞按钮:点赞按钮点赞后,再次点击异常(bug:5370) Self.praiseButton.userInteractionEnabled = NO; // [Self.praiseButton setSelect:YES animation:YES]; }else { ShowMessage(@"点赞失败", NO); } }]; } - (void)closeEvent:(UIButton*)btn { [self dismissControllerAnimated:YES completion:nil]; } - (void)headClick:(UIButton*)btn { if ([self.delegate respondsToSelector:@selector(answerDetailGoToOriginContent:presentedController:)]) { [self.delegate answerDetailGoToOriginContent:self.commentBO presentedController:self]; } } - (void)askBtnEvent:(UIButton*)btn { if ([self.delegate respondsToSelector:@selector(goToAskDetail:presentedController:)]) { [self.delegate goToAskDetail:self.commentBO presentedController:self]; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } /* #pragma mark - Navigation // In a storyboard-based application, you will often want to do a little preparation before navigation - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender { // Get the new view controller using [segue destinationViewController]. // Pass the selected object to the new view controller. } */ @end