|
//
// hotAskCommentController.m
// ThePaperBase
//
// Created by scar1900 on 15/8/10.
// Copyright (c) 2015年 scar1900. All rights reserved.
//
#import "hotAskCommentController.h"
#import "writeCommentAndAskController.h"
#import "loginHomeController.h"
#import "HotCommentTableViewVC.h"
#import "HotAnswerTableViewVC.h"
#import "imageShareContent.h"
@interface hotAskCommentController ()<ATPagingViewDelegate,UIGestureRecognizerDelegate,writeContentDelegate,HotCommentDelegate,hotAnswerTableDelegate>
{
UISwipeGestureRecognizer *swipeGesture;
}
@property(nonatomic, strong)UIView *backView;
@property(nonatomic, strong)UIButton *hotCommentBtn;
@property(nonatomic, strong)UIButton *hotAnswerBtn;
@property(nonatomic, strong)ATPagingView *pageView;
@property(nonatomic, strong)NSMutableArray *pageViewControllers;
@property(nonatomic, strong)NSMutableArray *viewControllers;
@property(nonatomic, strong)writeCommentAndAskController *writeCommentContentVC;
//@property(nonatomic, strong)UILabel *markLabel;
@end
@implementation hotAskCommentController
- (void)viewDidLoad {
[super viewDidLoad];
[MobClick event:@"5"];
self.titleStr = @"热赞榜";
self.view.backgroundColor = [UIColor clearColor];
self.view.frame = CGRectMake(0, CGRectGetHeight(self.naviBar.bounds)-1, rect_screen.size.width, rect_screen.size.height-CGRectGetHeight(self.naviBar.bounds)+1);
self.backView.frame = self.view.frame;
[self.view addSubview:self.backView];
[self addTabButtns];
[self addPageView];
swipeGesture = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeHandler:)];
swipeGesture.direction = UISwipeGestureRecognizerDirectionLeft;
swipeGesture.delegate = self;
[self.backView addGestureRecognizer:swipeGesture];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
- (void)needrefreshNightMode:(id)sender{
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
[_hotCommentBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateSelected];
[_hotCommentBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
[_hotAnswerBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateSelected];
[_hotAnswerBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
_pageView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)swipeHandler:(UISwipeGestureRecognizer*)gestureRecognizer{
if (self.pageView.currentPageIndex == 0 ) {
self.hotAnswerBtn.selected = !self.hotAnswerBtn.selected;
self.hotCommentBtn.selected = !self.hotCommentBtn.selected;
self.pageView.currentPageIndex = 1;
/**
* bug:5014
*/
[CoreAnimationEffect animationPushRight:self.pageView];
}else{
self.hotCommentBtn.selected = !self.hotCommentBtn.selected;
self.hotAnswerBtn.selected = !self.hotAnswerBtn.selected;
self.pageView.currentPageIndex = 0;
/**
* bug:5014
*/
[CoreAnimationEffect animationPushLeft:self.pageView];
}
}
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
return YES;
}
- (void)backHandler {
((MLNavigationController *)self.navigationController).canDragBack = YES;
[self.navigationController popViewControllerAnimated:YES];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UIView*)backView {
if (!_backView) {
_backView = [[UIView alloc]initWithFrame:CGRectMake(0,80,rect_screen.size.width, rect_screen.size.height-CGRectGetHeight(self.naviBar.bounds))];
_backView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
}
return _backView;
}
- (UIButton*)hotCommentBtn {
if (!_hotCommentBtn) {
_hotCommentBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_hotCommentBtn setTitle:@"热评论" forState:UIControlStateNormal];
_hotCommentBtn.titleLabel.font = appFont(16, NO);
[_hotCommentBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateSelected];
[_hotCommentBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
_hotCommentBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
[_hotCommentBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_hotCommentBtn.frame = CGRectMake(10, 0, rect_screen.size.width/2-10.5, 30);
[_hotCommentBtn addTarget:self action:@selector(hotCommentBtnEvent:) forControlEvents:UIControlEventTouchUpInside];
// UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_hotCommentBtn.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(4, 4)];
// CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
// maskLayer.frame = _hotCommentBtn.bounds;
// maskLayer.path = maskPath.CGPath;
// _hotCommentBtn.layer.mask = maskLayer;
}
return _hotCommentBtn;
}
- (UIButton*)hotAnswerBtn {
if (!_hotAnswerBtn) {
_hotAnswerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[_hotAnswerBtn setTitle:@"热回答" forState:UIControlStateNormal];
[_hotAnswerBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:BLUECOLOR]) forState:UIControlStateSelected];
[_hotAnswerBtn setBackgroundImage:imageWithUIColor([UIColor colorWithHexString:LIGHTGRAY]) forState:UIControlStateNormal];
_hotAnswerBtn.titleLabel.textAlignment = NSTextAlignmentCenter;
_hotAnswerBtn.titleLabel.font = appFont(16, NO);
[_hotAnswerBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
_hotAnswerBtn.frame = CGRectMake(rect_screen.size.width/2+0.5,0 , rect_screen.size.width/2-10.5, 30);
[_hotAnswerBtn addTarget:self action:@selector(hotAnswerBtn:) forControlEvents:UIControlEventTouchUpInside];
// UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:_hotAnswerBtn.bounds byRoundingCorners:UIRectCornerBottomRight | UIRectCornerTopRight cornerRadii:CGSizeMake(4, 4)];
// CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
// maskLayer.frame = _hotAnswerBtn.bounds;
// maskLayer.path = maskPath.CGPath;
// _hotAnswerBtn.layer.mask = maskLayer;
}
return _hotAnswerBtn;
}
- (ATPagingView*)pageView {
if (!_pageView) {
_pageView = [[ATPagingView alloc]initWithFrame:CGRectMake(0,
40,
rect_screen.size.width,
CGRectGetHeight(self.backView.bounds) - 40)];
_pageView.gapBetweenPages = 0;
_pageView.recyclingEnabled = NO;
_pageView.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
_pageView.delegate = self;
_pageView.scrollView.bounces = NO;
_pageView.scrollView.scrollEnabled = NO;
}
return _pageView;
}
//- (UIView*)menuRubberView {
// if (!_menuRubberView) {
// _menuRubberView = [[UIView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.notificationBtn.frame)/2 -20,40-3, 40, 3)];
// _menuRubberView.backgroundColor = [UIColor colorWithHexString:BLUECOLOR];
// }
// return _menuRubberView;
//}
#pragma mark - add subviews
- (void)addTabButtns {
[self.backView addSubview:self.hotCommentBtn];
[self.backView addSubview:self.hotAnswerBtn];
}
- (void)addPageView {
self.viewControllers = [NSMutableArray arrayWithObjects:@"HotCommentTableViewVC",@"HotAnswerTableViewVC",nil];
[self.viewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
if (nil == self.pageViewControllers) {
self.pageViewControllers = [NSMutableArray array];
}
if ([obj isKindOfClass:[UIViewController class]]) {
[self.pageViewControllers addObject:obj];
[self addChildViewController:obj];
} else {
[self.pageViewControllers addObject:[NSNull null]];
}
}];
[self.backView addSubview:self.pageView];
self.hotCommentBtn.selected = YES;
[self.pageView reloadData];
}
#pragma mark - button handler
- (void)hotCommentBtnEvent:(UIButton*)btn {
if (btn.selected == YES) {
HotCommentTableViewVC *Vc = self.pageViewControllers[0];
[Vc.tableView setContentOffset:CGPointZero animated:YES];
return;
}
btn.selected = !btn.selected;
if (btn.selected) {
self.pageView.currentPageIndex = 0;
[CoreAnimationEffect animationPushLeft:self.pageView];
self.hotCommentBtn.selected = YES;
self.hotAnswerBtn.selected = NO;
}
}
- (void)hotAnswerBtn:(UIButton*)btn {
if (btn.selected == YES) {
HotAnswerTableViewVC *Vc = self.pageViewControllers[1];
[Vc.tableView setContentOffset:CGPointZero animated:YES];
return;
}
btn.selected = !btn.selected;
if (btn.selected) {
self.pageView.currentPageIndex = 1;
[CoreAnimationEffect animationPushRight:self.pageView];
self.hotCommentBtn.selected = NO;
self.hotAnswerBtn.selected = YES;
}
}
- (void)tapNaviBar:(id)sender {
if (self.hotAnswerBtn.selected) {
HotAnswerTableViewVC *Vc = self.pageViewControllers[1];
[Vc.tableView setContentOffset:CGPointZero animated:YES];
}else{
HotCommentTableViewVC *Vc = self.pageViewControllers[0];
[Vc.tableView setContentOffset:CGPointZero animated:YES];
}
}
- (void)presentWriteToUser:(commentObjectVO *)commentBO {
self.writeCommentContentVC = [[writeCommentAndAskController alloc]init];
self.writeCommentContentVC.type = commentForUserType;
self.writeCommentContentVC.nodeId = commentBO.contId;
self.writeCommentContentVC.commentBO = commentBO;
self.writeCommentContentVC.delegate = self;
self.writeCommentContentVC.view.frame = self.view.bounds;
[self presentController:self.writeCommentContentVC animated:YES completion:^{
}];
}
- (void)commentPushToLoginView {
loginHomeController *vc = loginHomeController.new;
[self.navigationController pushViewController:vc animated:YES];
}
- (void)dismissWriteContent:(commentAndAskType)type {
__weak typeof(self) Self = self;
[self dismissViewController:self.writeCommentContentVC animated:YES completion:^{
Self.writeCommentContentVC = nil;
}];
}
- (void)commentSuccess:(commentAndAskType)type {
__weak typeof(self) Self = self;
[self dismissViewController:self.writeCommentContentVC animated:YES completion:^{
if (Self.writeCommentContentVC.type == commentForUserType) {
[Self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// if ([obj isKindOfClass:[HotCommentTableViewVC class]]) {
// [(HotCommentTableViewVC*)obj manualRefresh];
// }
}];
}else if (Self.writeCommentContentVC.type == askType || Self.writeCommentContentVC.type == askForUserType) {
[Self.pageViewControllers enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
// if ([obj isKindOfClass:[HotAnswerTableViewVC class]]) {
// [(HotAnswerTableViewVC*)obj manualRefresh];
// }
}];
}
Self.writeCommentContentVC = nil;
}];
}
#pragma mark - pageView delegate
- (NSInteger)numberOfPagesInPagingView:(ATPagingView *)pagingView {
return self.viewControllers.count;
}
- (UIView *)viewForPageInPagingView:(ATPagingView *)pagingView atIndex:(NSInteger)index {
if (self.pageViewControllers[index] == [NSNull null]) {
NSString *className = self.viewControllers[index];
Class class = NSClassFromString(className);
UIViewController *vc = [[class alloc] init];
self.pageViewControllers[index] = vc;
if(0 == index){
[(HotCommentTableViewVC *)vc setDelegate:self];
}else if(1 == index){
[(HotAnswerTableViewVC *)vc setDelegate:self];
// letterController *vc = self.pageViewControllers[1];
}
[self addChildViewController:vc];
}
return ((UIViewController*)self.pageViewControllers[index]).view;
}
- (void)currentPageDidChangeInPagingView:(ATPagingView *)pageView {
if (pageView.currentPageIndex == 0) {
self.hotCommentBtn.selected = YES;
self.hotAnswerBtn.selected = NO;
}else if (pageView.currentPageIndex == 1) {
// letterController *vc = self.pageViewControllers[1];
// [vc scrollTableViewToTop];
self.hotCommentBtn.selected = NO;
self.hotAnswerBtn.selected = YES;
}
}
- (void)pagesDidChangeInPagingView:(ATPagingView *)pageView {
}
- (void)pagingViewWillBeginMoving:(ATPagingView *)pageView {
}
- (void)pagingViewdDidScroll:(UIScrollView *)scrollerView {
if (self.pageView.currentPageIndex == 0) {
}else if (self.pageView.currentPageIndex == 1) {
}
// CGFloat width = (rect_screen.size.width-30);
// CGFloat width = 40;
// CGFloat scrollOffsetX = scrollerView.contentOffset.x;
// CGRect rect = self.menuRubberView.frame;
// CGFloat scale = scrollOffsetX/(rect_screen.size.width*2);
// CGFloat offset = width*scale;
// rect.origin.x = 15+offset;
// self.menuRubberView.frame = rect;
}
-(void)hotAnswerTableToShare:(UIImage *)img contentBO:(contentObjectBO *)contentBO{
imageShareContent *askListshareContentView = [[imageShareContent alloc]initWithFrame:CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
CGRectGetHeight(self.view.bounds))];
askListshareContentView.contentBO = contentBO;
askListshareContentView.shareImg = img;
askListshareContentView.baseController = self;
askListshareContentView.sharestyle = shareNewsStyle;
[askListshareContentView presentShareContentInView:self.view sender:nil];
}
-(void)hotCommentTableToShare:(UIImage *)img contentBO:(contentObjectBO *)contentBO{
imageShareContent *askListshareContentView = [[imageShareContent alloc]initWithFrame:CGRectMake(0,
0,
CGRectGetWidth(self.view.bounds),
CGRectGetHeight(self.view.bounds))];
askListshareContentView.contentBO = contentBO;
askListshareContentView.shareImg = img;
askListshareContentView.baseController = self;
askListshareContentView.sharestyle = shareNewsStyle;
[askListshareContentView presentShareContentInView:self.view sender:nil];
}
@end
|