|
//
// channelMenuView.m
// ThePaperDemo
//
// Created by Scar on 14-9-5.
// Copyright (c) 2014年 scar1900. All rights reserved.
//
#import "channelMenuView.h"
#import "ChannelCollectCell.h"
#import "visualDataMethod.h"
//#import "fontSizeSlideCell.h"
#import "channelMenuLoginButton.h"
#import "TPSelectButton.h"
#import "UIControl+runTimeProtect.h"
#define CHANNELBUTTONTAG 3000
#define CHANNELLABELTAG 3500
#define LOGINBTNTAG 3600
@interface fontLabel : UILabel {
}
@property(nonatomic, strong)UIImageView *imageView;
@property(nonatomic, assign)BOOL isSelected;
@end
@implementation fontLabel
@synthesize isSelected = _isSelected;
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.backgroundColor = [UIColor clearColor];
self.font = [UIFont systemFontOfSize:15];
self.textAlignment = NSTextAlignmentLeft;
self.textColor = [UIColor colorWithHexString:@"0x555555"];
[self addSubview:self.imageView];
}
return self;
}
- (UIImageView*)imageView {
if (!_imageView) {
_imageView = [[UIImageView alloc]initWithFrame:CGRectMake(CGRectGetWidth(self.bounds)-20, 0, 20, 20)];
_imageView.image = Image(@"Button/select.png");
}
return _imageView;
}
- (void)setIsSelected:(BOOL)selected {
_isSelected = selected;
self.imageView.hidden = !selected;
}
- (void)layoutSubviews {
[super layoutSubviews];
self.imageView.frame = CGRectMake(CGRectGetWidth(self.bounds)-20, CGRectGetHeight(self.bounds)/2-10, 20, 20);
}
@end
@interface channelMenuView()<UITableViewDataSource,UITableViewDelegate> {
TPSelectButton *fontSelectBtn;
TPSelectButton *readModeBtn;
BOOL isFirstShow;
BOOL isFromNoti;
CGFloat cardPadding;
CGFloat cardWidthAndHeight;
CGFloat chennelCardCellHeight;
CGFloat loginBtnHeight;
CGFloat selectBtnHeight;
CGFloat selectBtnWidth;
CGFloat menuHeight;
}
@property(nonatomic, strong)UIView *backgroundView;
@property(nonatomic, strong)UITableView *menuView;
@property(nonatomic, strong)UIView *menuBack;
@property(nonatomic, strong)UIButton *backButton;
@property(nonatomic, strong)UIPanGestureRecognizer *panGesture;
@property(nonatomic, strong)NSString *isFirstShowMenu;
@end
@implementation channelMenuView
@synthesize selectIndex;
@synthesize snapView = _snapView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
self.backgroundColor = [UIColor clearColor];
self.selectIndex = -1;
self.isFirstShowMenu = @"1";
isFromNoti = NO;
if (IS_IPHONE_6P) {
cardPadding = 88/3;
cardWidthAndHeight = (rect_screen.size.width-5*cardPadding)/4;
chennelCardCellHeight = 3*cardPadding + 2*cardWidthAndHeight;
}else if (IS_IPHONE_6) {
cardPadding = 15;
cardWidthAndHeight = (rect_screen.size.width-5*cardPadding)/4;
chennelCardCellHeight = 3*cardPadding + 2*cardWidthAndHeight;
}else {
cardPadding = 15;
cardWidthAndHeight = (rect_screen.size.width-5*cardPadding)/4;
chennelCardCellHeight = 3*cardPadding + 2*cardWidthAndHeight;
}
loginBtnHeight = 40;
selectBtnHeight = 50;
selectBtnWidth = (rect_screen.size.width-30)/4;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(closeByItemSelected:) name:SELECTCHANNEL object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginSuccess:) name:HAVELOGIN object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(loginOutSuccess:) name:HAVELOGINOUT object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(needrefreshNightMode:) name:REFRESHAFTERNIGHTMODE object:nil];
}
return self;
}
- (void)showMenuInView:(UIView *)view naviHeight:(CGFloat)naviHeight{
self.backgroundView.frame = view.bounds;
[self addSubview:self.backgroundView];
UIToolbar *toolBar = [[UIToolbar alloc]init];
if ([toolBar respondsToSelector:@selector(setBarTintColor:)]) {
self.snapView.frame = self.backgroundView.bounds;
[self.backgroundView addSubview:self.snapView];
}else {
self.backgroundView.backgroundColor = [UIColor colorWithHexString:@"0x3e3c3d"];
}
toolBar = nil;
menuHeight = chennelCardCellHeight + cardPadding + loginBtnHeight + cardPadding + 2*selectBtnHeight + cardPadding/2+ cardPadding + 35;
self.menuBack.frame = CGRectMake(0, 0-menuHeight+40-25, CGRectGetWidth(view.bounds), menuHeight+25);
[self addSubview:self.menuBack];
self.menuView.frame = CGRectMake(0, 25, CGRectGetWidth(view.bounds), menuHeight);
[self.menuBack addSubview:self.menuView];
[self.menuBack addGestureRecognizer:self.panGesture];
self.backButton.frame = CGRectMake(0, menuHeight, CGRectGetWidth(view.bounds), CGRectGetHeight(view.bounds)-menuHeight);
[self addSubview:self.backButton];
if ([UIView respondsToSelector:@selector(animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)]) {
[UIView animateWithDuration:0.5
delay:0.0
usingSpringWithDamping:0.7
initialSpringVelocity:4.0
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:^{
self.backgroundView.alpha = 1;
CGRect frame = self.menuBack.frame;
frame.origin.y = -25;
self.menuBack.frame = frame;
} completion:^(BOOL finished) {
self.userInteractionEnabled = YES;
if ([self.isFirstShowMenu intValue] == 1) {
[self refreshMsgMark];
self.isFirstShowMenu = @"0";
self.menuView.delaysContentTouches = NO;
for (id obj in self.menuView.subviews)
{
if ([obj respondsToSelector:@selector(setDelaysContentTouches:)])
{
[obj setDelaysContentTouches:NO];
}
}
}
}];
} else {
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:^{
self.backgroundView.alpha = 0.8;
CGRect frame = self.menuBack.frame;
frame.origin.y = -25;
self.menuBack.frame = frame;
} completion:^(BOOL finished) {
if ([self.isFirstShowMenu intValue] == 1) {
self.userInteractionEnabled = YES;
[self refreshMsgMark];
self.isFirstShowMenu = @"0";
self.menuView.delaysContentTouches = NO;
for (id obj in self.menuView.subviews)
{
if ([obj respondsToSelector:@selector(setDelaysContentTouches:)])
{
[obj setDelaysContentTouches:NO];
}
}
}
}];
}
}
- (void)closeWithCompletion:(void (^)(void))completion {
void (^closeMenu)(void) = ^{
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:^ {
CGRect frame = self.menuView.frame;
frame.origin.y = 0-menuHeight+40-25;
self.menuBack.frame = frame;
self.backgroundView.alpha = 0;
} completion:^(BOOL finished) {
[self.menuBack removeFromSuperview];
[self.menuView removeFromSuperview];
[self.backButton removeFromSuperview];
[self.backgroundView removeFromSuperview];
if (completion) {
completion();
}
if (self.closeCompletionHandler) {
self.closeCompletionHandler();
}
}];
};
self.backButton.backgroundColor = [UIColor clearColor];
[UIView animateWithDuration:0.3
animations:^ {
CGRect frame = self.menuBack.frame;
frame.origin.y = 0;
self.menuBack.frame = frame;
} completion:^(BOOL finished) {
closeMenu();
}];
}
- (UIPanGestureRecognizer*)panGesture {
if (!_panGesture) {
_panGesture = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureHandler:)];
}
return _panGesture;
}
- (UIView*)backgroundView {
if (!_backgroundView) {
// _backgroundView.backgroundColor = [UIColor colorWithHexString:@"0x3e3c3d"];
// UIToolbar *toolBar = [[UIToolbar alloc]init];
// if ([toolBar respondsToSelector:@selector(setBarTintColor:)]) {
// _backgroundView = [[JCRBlurView alloc]initWithFrame:CGRectZero];
// ((JCRBlurView*)_backgroundView).blurTintColor = [UIColor colorWithHexString:@"0x3e3c3d"];
// }else {
// _backgroundView = [[UIView alloc]initWithFrame:CGRectZero];
// _backgroundView.backgroundColor = [UIColor colorWithHexString:@"0x3e3c3d"];
// }
// _backgroundView.clipsToBounds = YES;
// _backgroundView.alpha = 0;
// toolBar = nil;
_backgroundView = [[UIView alloc]initWithFrame:CGRectZero];
_backgroundView.backgroundColor = [UIColor clearColor];
_backgroundView.alpha = 0;
_backgroundView.clipsToBounds = YES;
}
return _backgroundView;
}
- (UITableView*)menuView {
if (!_menuView) {
_menuView = [[UITableView alloc]initWithFrame:CGRectZero style:UITableViewStylePlain];
_menuView.backgroundColor = [UIColor clearColor];
_menuView.delegate = self;
_menuView.dataSource = self;
_menuView.scrollEnabled = NO;
_menuView.separatorStyle = UITableViewCellSeparatorStyleNone;
_menuView.separatorColor=[UIColor clearColor];
_menuView.delaysContentTouches = NO;
[_menuView reloadData];
}
return _menuView;
}
- (UIView*)menuBack {
if (!_menuBack) {
_menuBack = [[UIView alloc]initWithFrame:CGRectZero];
}
_menuBack.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
return _menuBack;
}
- (UIButton*)backButton {
if (!_backButton) {
_backButton = [UIButton buttonWithType:UIButtonTypeCustom];
_backButton.backgroundColor = [UIColor clearColor];
_backButton.alpha = 0.8;
[_backButton addTarget:self action:@selector(backBtnHandle:) forControlEvents:UIControlEventTouchUpInside];
}
return _backButton;
}
- (void)setSnapView:(UIView *)view {
_snapView = view;
}
- (void)backBtnHandle:(UIButton*)btn {
[self closeWithCompletion:nil];
}
- (void)layoutSubviews {
[super layoutSubviews];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
/**
* bug:5637(其他:app放置在后台一段时间,热启动,切换到夜间模式,即闪退)
*/
}
#pragma mark - table view delegate and datasource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row == 0) {
return chennelCardCellHeight;
}else if (indexPath.row == 1) {
return cardPadding + loginBtnHeight;
}else if (indexPath.row == 2) {
return cardPadding + 2*selectBtnHeight + cardPadding/2 + cardPadding;;
}else return 35;
}
- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifer = @"channelMenuCell";
if (indexPath.row == 0) {
cellIdentifer = @"channelCollectCell";
}else if (indexPath.row == 1) {
cellIdentifer = @"buttonSelectCell";
}else if (indexPath.row == 2) {
cellIdentifer = @"fontSelectCell";
}else if (indexPath.row == 3) {
cellIdentifer = @"dragMenuCell";
}
if (indexPath.row == 0) {
ChannelCollectCell *cell = (ChannelCollectCell*)[tableView dequeueReusableCellWithIdentifier:cellIdentifer];
if (nil == cell) {
cell = [[ChannelCollectCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIView *lineView = [UIView new];
lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
// lineView.image = Image(@"Button/menuLine.png");
[cell.contentView addSubview:lineView];
lineView.tag = 50;
UIEdgeInsets paddingInset = UIEdgeInsetsMake(1, 15, CGRectGetHeight(cell.contentView.bounds)-1, 15);
__block UIView *view = cell.contentView;
[lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_left).offset(paddingInset);
make.right.equalTo(view.mas_right).offset(paddingInset);
make.top.equalTo(view.mas_top).offset(paddingInset);
make.height.equalTo(@(1));
}];
}
UIView *line = [cell viewWithTag:50];
line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
if ([TPUserDefault instance].channldataList.count > 0) {
cell.dataList = [TPUserDefault instance].channldataList;
}
return cell;
}else if (indexPath.row == 1) { //登陆、用户信息按钮
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
if (nil == cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
[self addLineInCell:cell];
channelMenuLoginButton *loginBtn = [[channelMenuLoginButton alloc]initWithFrame:CGRectZero];
loginBtn.tag = LOGINBTNTAG;
[loginBtn addTarget:self action:@selector(loginHandler:) forControlEvents:UIControlEventTouchUpInside];
loginBtn.uxy_acceptEventInterval = 0.5;
[cell.contentView addSubview:loginBtn];
[loginBtn makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(cell.contentView.left).offset(cardPadding);
make.right.equalTo(cell.contentView.right).offset(-cardPadding);
make.bottom.equalTo(cell.contentView.bottom);
make.height.equalTo(@40);
}];
for (id obj in cell.subviews)
{
if ([obj respondsToSelector:@selector(setDelaysContentTouches:)])
{
[obj setDelaysContentTouches:NO];
}
}
}
UIView *line = [cell viewWithTag:51];
line.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
channelMenuLoginButton *loginBtn = (channelMenuLoginButton*)[cell.contentView viewWithTag:LOGINBTNTAG];
[loginBtn refreshLoginBtn];
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
return cell;
}else if (indexPath.row == 2) {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
if (nil == cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
for (id obj in cell.subviews)
{
if ([obj respondsToSelector:@selector(setDelaysContentTouches:)])
{
[obj setDelaysContentTouches:NO];
}
}
}
[self addButtonOfCell:cell];
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
return cell;
}else {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifer];
if (nil == cell) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifer];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
UIImageView *arrowImageView = [[UIImageView alloc]initWithFrame:CGRectMake(160-15, 5, 30, 10)];
arrowImageView.image = Image(@"Button/dragArrow.png");
arrowImageView.userInteractionEnabled = YES;
[cell.contentView addSubview:arrowImageView];
[arrowImageView makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(cell.contentView.centerX);
make.top.equalTo(cell.contentView.top).with.offset(5);
make.width.equalTo(@30);
make.height.equalTo(@10);
}];
}
cell.backgroundColor = [UIColor colorWithHexString:BackGroundColor];
return cell;
}
return nil;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
if (indexPath.row == 3) {
[self closeWithCompletion:nil];
}
}
- (void)closeByItemSelected:(NSNotification*)notification {
if (notification.object) {
self.selectIndex = [notification.object intValue];
[TPUserDefault instance].currentPageIndex = self.selectIndex;
[self closeWithCompletion:nil];
}
}
- (void)addLineInCell:(UITableViewCell*)cell {
UIView *lineView = [UIView new];
lineView.backgroundColor = [UIColor colorWithHexString:LINECOLOR];
[cell.contentView addSubview:lineView];
lineView.tag = 51;
UIEdgeInsets paddingInset = UIEdgeInsetsMake(1, cardPadding, CGRectGetHeight(cell.contentView.bounds)-1, cardPadding);
__block UIView *view = cell.contentView;
[lineView makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(view.mas_left).offset(paddingInset);
make.right.equalTo(view.mas_right).offset(paddingInset);
make.top.equalTo(view.mas_top).offset(paddingInset);
make.height.equalTo(@(1));
}];
}
- (void)addButtonOfCell:(UITableViewCell*)cell {
for (int i=0; i<8; i++) {
TPSelectButton *button = (TPSelectButton*)[cell viewWithTag:CHANNELBUTTONTAG + i];
if (!button) {
switch (i) {
case 0:
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(followHandler:)];
[button setBUttonNormalImage:Image(@"Button/followBtn.png")
highLightImage:Image(@"Button/followBtn_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"跟踪";
break;
case 1:
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(collectHandler:)];
[button setBUttonNormalImage:Image(@"Button/collectBtn.png")
highLightImage:Image(@"Button/collectBtn_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"收藏";
break;
case 2:
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(topicHandler:)];
[button setBUttonNormalImage:Image(@"Button/topicSettingIcon.png")
highLightImage:Image(@"Button/topicSettingIcon_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"话题";
break;
case 3:
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(messageHandler:)];
[button setBUttonNormalImage:Image(@"Button/messageSettingIcon.png")
highLightImage:Image(@"Button/messageSettingIcon_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"消息";
break;
case 4:
if ([[TPUserDefault instance].isUseSystemFont intValue] == 0) {
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(selectSong:)];
[button setBUttonNormalImage:Image(@"Button/songFontIcon.png")
highLightImage:Image(@"Button/songFontIcon_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"宋体";
}else {
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(selectSystemFont:)];
[button setBUttonNormalImage:Image(@"Button/systemFontIcon.png")
highLightImage:Image(@"Button/systemFontIcon_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"系统字体";
}
fontSelectBtn = button;
break;
case 5:
if ([[TPUserDefault instance].isNightMode intValue] == 0) {
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(changeNightMode:)];
[button setBUttonNormalImage:Image(@"Button/nightMode.png")
highLightImage:Image(@"Button/nightMode_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"夜间模式";
}else {
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(changeDayMode:)];
[button setBUttonNormalImage:Image(@"Button/dayMode.png")
highLightImage:Image(@"Button/dayMode_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"日间模式";
}
readModeBtn = button;
break;
case 6:
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(goToHaiBei:)];
[button setBUttonNormalImage:Image(@"Button/haibeiIcon.png")
highLightImage:Image(@"Button/haibeiIcon_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"海贝商城";
break;
case 7:
button = [[TPSelectButton alloc]initWithFrame:CGRectZero target:self selector:@selector(settingHandler:)];
[button setBUttonNormalImage:Image(@"Button/settingBtn.png")
highLightImage:Image(@"Button/settingBtn_s.png")
selectedImage:nil];
button.btnSize = CGSizeMake(selectBtnWidth, selectBtnHeight);
button.titleText = @"更多";
break;
default:
break;
}
button.imgSize = CGSizeMake(30, 30);
button.button.uxy_acceptEventInterval = 0.5;
/**
* bug:5588( 频道导航页:连续点击会连续跳出的几个菜单)
*/
button.tag = CHANNELBUTTONTAG + i;
button.backgroundColor = [UIColor clearColor];
[cell.contentView addSubview:button];
TPSelectButton *lastBtn = nil;
TPSelectButton *firstBtn = nil;
if (i>0) {
lastBtn = (TPSelectButton*)[cell viewWithTag:CHANNELBUTTONTAG + i-1];
firstBtn = (TPSelectButton*)[cell viewWithTag:CHANNELBUTTONTAG + 0];
}
if (!lastBtn) {
[button makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(cell.contentView.left).offset(15);
make.top.equalTo(cell.contentView.top).offset(cardPadding);
make.width.mas_equalTo(selectBtnWidth);
make.height.mas_equalTo(selectBtnHeight);
}];
}else {
if (i != 4) {
[button makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(lastBtn.right);
make.top.equalTo(lastBtn.top);
make.width.mas_equalTo(selectBtnWidth);
make.height.mas_equalTo(selectBtnHeight);
}];
}else{
[button makeConstraints:^(MASConstraintMaker *make) {
make.left.equalTo(cell.contentView.left).offset(15);
make.top.equalTo(firstBtn.bottom).offset(cardPadding/2);
make.width.mas_equalTo(selectBtnWidth);
make.height.mas_equalTo(selectBtnHeight);
}];
}
}
}
button.textLabel.textColor = [UIColor colorWithHexString:TextGray];
}
}
#pragma mark - msg mark logic
- (void)refreshMsgMark {
UITableViewCell *cell = [self.menuView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:2 inSection:0]];
TPSelectButton *followButton = (TPSelectButton*)[cell viewWithTag:CHANNELBUTTONTAG + 0];
TPSelectButton *topicButton = (TPSelectButton*)[cell viewWithTag:CHANNELBUTTONTAG + 2];
TPSelectButton *messageButton = (TPSelectButton*)[cell viewWithTag:CHANNELBUTTONTAG + 3];
if ([TPUserDefault instance].userBO) {
NSDictionary *dic = [TPUserDefault instance].msgMark;
if ([dic[@"trackMark"] longValue] > 0) {
[followButton.button addBadgeView:followButton.imgInset];
}else {
[followButton.button clearBadgeView];
}
// if ([dic[@"questionMark"] longValue] >0 || [dic[@"attendMark"] longValue] > 0) {
// [self.askButton.button addBadgeView];
// }else {
// [self.askButton.button clearBadgeView];
// }
if ([dic[@"createdTopicMark"] longValue] > 0 || [dic[@"attendTopicMark"] longValue] > 0) {
[topicButton.button addBadgeView:followButton.imgInset];
}else {
[topicButton.button clearBadgeView];
}
if([dic[@"questionMark"] longValue] >0 || [dic[@"attendMark"] longValue] >0||[dic[@"replyedMark"] longValue] >0 || [dic[@"letterMark"] longValue] >0){
[messageButton.button addBadgeView:followButton.imgInset];
}else{
[messageButton.button clearBadgeView];
}
}else {
[followButton.button clearBadgeView];
// [self.askButton.button clearBadgeView];
[topicButton.button clearBadgeView];
[messageButton.button clearBadgeView];
}
}
#pragma mark - pan gesture handler
- (void)panGestureHandler:(UIPanGestureRecognizer*)pangesture {
UIGestureRecognizerState state = pangesture.state;
CGPoint location = [pangesture locationInView:self.menuView];
NSIndexPath *indexPath = [self.menuView indexPathForRowAtPoint:location];
static CGPoint sourceLoaction;
static CGPoint originCenter;
static CGPoint endOffset;
switch (state) {
case UIGestureRecognizerStateBegan: {
if (indexPath) {
if (location.y >= self.menuView.frame.size.height - 40) {
sourceLoaction = location;
originCenter = pangesture.view.center;
}else {
sourceLoaction = CGPointMake(0, 0);
}
}
break;
}
case UIGestureRecognizerStateChanged: {
CGPoint offset = [pangesture translationInView:self.menuView];
if (sourceLoaction.y > 0) {
pangesture.view.center = CGPointMake(pangesture.view.center.x, pangesture.view.center.y + offset.y);
[pangesture setTranslation:CGPointMake(0, 0) inView:self.menuView];
endOffset = offset;
self.backgroundView.alpha = self.backgroundView.alpha + offset.y/500;
if (pangesture.view.center.y > originCenter.y) {
pangesture.view.center = originCenter;
return;
}
}
break;
}
default: {
if (sourceLoaction.y <= 0) {
break;
}
if (endOffset.y >= 0) {
CGFloat duration = 0.5;
if (endOffset.y > 20) {
duration = 4/endOffset.y;
}else if (endOffset.y<= 20 && endOffset.y > 10){
duration = 3/endOffset.y;
}else if (endOffset.y < 10) {
duration = 0.6;
}
if ([UIView respondsToSelector:@selector(animateWithDuration:delay:usingSpringWithDamping:initialSpringVelocity:options:animations:completion:)]) {
[UIView animateWithDuration:duration
delay:0.0
usingSpringWithDamping:0.7
initialSpringVelocity:4.0
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:^{
self.backgroundView.alpha = 1;
CGRect frame = self.menuBack.frame;
frame.origin.y = -25;
self.menuBack.frame = frame;
} completion:^(BOOL finished) {
}];
} else {
if (duration == 0.5) {
duration = 0.3;
}
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:^{
self.backgroundView.alpha = 0.8;
CGRect frame = self.menuBack.frame;
frame.origin.y = -25;
self.menuBack.frame = frame;
} completion:^(BOOL finished) {
}];
}
}else {
CGFloat duration = 0.3;
if ((0-endOffset.y) > 20) {
duration = 0-4/endOffset.y;
}else if ((0-endOffset.y)<= 20 && (0-endOffset.y) > 10){
duration = 0-3/endOffset.y;
}else if ((0-endOffset.y) < 10) {
duration = 0.5;
}
[UIView animateWithDuration:duration
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState|UIViewAnimationOptionCurveEaseInOut
animations:^ {
CGRect frame = self.menuView.frame;
frame.origin.y = 0-menuHeight+40-25;
self.menuBack.frame = frame;
self.backgroundView.alpha = 0;
} completion:^(BOOL finished) {
[self.menuBack removeFromSuperview];
[self.menuView removeFromSuperview];
[self.backButton removeFromSuperview];
[self.backgroundView removeFromSuperview];
[self.snapView removeFromSuperview];
if (self.closeCompletionHandler) {
self.closeCompletionHandler();
}
}];
}
sourceLoaction = CGPointMake(0, 0);
break;
}
}
}
#pragma mark - channel buttons event
//登陆
- (void)loginHandler:(UIButton*)btn {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if (![TPUserDefault instance].userBO) {
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOLOGIN object:nil];
}else {
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOUSERINFO object:nil];
}
});
}
//设置
- (void)settingHandler:(UIButton*)btn {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOSETTINGS object:nil];
});
}
//跟踪
- (void)followHandler:(UIButton*)btn {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[TPUserDefault instance].msgMark];
[dic setValue:@(0) forKey:@"trackMark"];
[TPUserDefault instance].msgMark = dic;
[btn clearBadgeView];
}
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOFOLLOW object:nil];
});
}
//收藏
- (void)collectHandler:(UIButton*)btn {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOCOLLECT object:nil];
});
}
//话题
- (void)topicHandler:(UIButton*)btn {
[MobClick event:@"71"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
if ([TPUserDefault instance].userBO) {
NSMutableDictionary *dic = [NSMutableDictionary dictionaryWithDictionary:[TPUserDefault instance].msgMark];
[dic setValue:@(0) forKey:@"createdTopicMark"];
[dic setValue:@(0) forKey:@"attendTopicMark"];
[TPUserDefault instance].msgMark = dic;
[btn clearBadgeView];
}
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHMYTOPICCENTER object:nil];
});
}
//消息
- (void)messageHandler:(UIButton*)btn {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[btn clearBadgeView];
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOMESSAGE object:nil];
});
}
//评分
- (void)goToMask:(UIButton*)btn {
NSString *str = [NSString stringWithFormat:@"http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?id=%@&pageNumber=0&sortOrdering=2&type=Purple+Software&mt=8",@"878962716" ];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
}
//海贝商城
- (void)goToHaiBei:(UIButton*)btn {
[MobClick event:@"88"];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOHAIBEI object:nil];
});
}
//追问
- (void)anserBtnHandler:(UIButton*)btn {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.15 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] postNotificationName:PUSHTOASK object:nil];
});
}
- (void)changeNightMode:(UIButton*)btn {
[readModeBtn.button removeTarget:self action:@selector(changeNightMode:) forControlEvents:UIControlEventTouchUpInside];
[readModeBtn.button addTarget:self action:@selector(changeDayMode:) forControlEvents:UIControlEventTouchUpInside];
[readModeBtn setBUttonNormalImage:Image(@"Button/dayMode.png")
highLightImage:Image(@"Button/dayMode_s.png")
selectedImage:nil];
readModeBtn.titleText = @"日间模式";
[TPUserDefault instance].isNightMode = @"1";
if (!isFromNoti) {
[[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERNIGHTMODE object:nil];
}
if (changeStause) {
changeStause();
}
[UIView animateWithDuration:0.3 animations:^{
[self.menuView reloadData];
TPWindow *window = (TPWindow*)[[UIApplication sharedApplication]keyWindow];
[window setMaskAfterOpenNightMode];
} completion:^(BOOL finished) {
}];
}
- (void)changeDayMode:(UIButton*)btn {
[readModeBtn.button removeTarget:self action:@selector(changeDayMode:) forControlEvents:UIControlEventTouchUpInside];
[readModeBtn.button addTarget:self action:@selector(changeNightMode:) forControlEvents:UIControlEventTouchUpInside];
[readModeBtn setBUttonNormalImage:Image(@"Button/nightMode.png")
highLightImage:Image(@"Button/nightMode_s.png")
selectedImage:nil];
readModeBtn.titleText = @"夜间模式";
[TPUserDefault instance].isNightMode = @"0";
[MobClick event:@"26"];
if (!isFromNoti) {
[[NSNotificationCenter defaultCenter]postNotificationName:REFRESHAFTERNIGHTMODE object:nil];
}
if (changeStause) {
changeStause();
}
[UIView animateWithDuration:0.3 animations:^{
[self.menuView reloadData];
TPWindow *window = (TPWindow*)[[UIApplication sharedApplication]keyWindow];
[window setNoNightModeMask];
} completion:^(BOOL finished) {
}];
}
- (void)changeStauseBarStyle:(void (^)())block {
changeStause = [block copy];
}
//选择宋体
- (void)selectSong:(UIButton*)btn {
[MobClick event:@"22"];
[fontSelectBtn.button removeTarget:self action:@selector(selectSong:) forControlEvents:UIControlEventTouchUpInside];
[fontSelectBtn.button addTarget:self action:@selector(selectSystemFont:) forControlEvents:UIControlEventTouchUpInside];
[fontSelectBtn setBUttonNormalImage:Image(@"Button/systemFontIcon.png")
highLightImage:Image(@"Button/systemFontIcon_s.png")
selectedImage:nil];
fontSelectBtn.titleText = @"系统字体";
[TPUserDefault instance].isUseSystemFont = @"1";
[self.menuView reloadData];
if (changeFont) {
changeFont();
}
}
//选择系统字体
- (void)selectSystemFont:(UIButton*)btn {
[fontSelectBtn.button removeTarget:self action:@selector(selectSystemFont:) forControlEvents:UIControlEventTouchUpInside];
[fontSelectBtn.button addTarget:self action:@selector(selectSong:) forControlEvents:UIControlEventTouchUpInside];
[fontSelectBtn setBUttonNormalImage:Image(@"Button/songFontIcon.png")
highLightImage:Image(@"Button/songFontIcon_s.png")
selectedImage:nil];
fontSelectBtn.titleText = @"宋体";
[TPUserDefault instance].isUseSystemFont = @"0";
[self.menuView reloadData];
if (changeFont) {
changeFont();
}
}
- (void)changeFont:(void (^)())block {
changeFont = [block copy];
}
#pragma mark - remote delegate and call back
//- (void)startWaitCursor:(int)actionTag {
//
//}
//
//- (void)stopWaitCursor:(int)actionTag {
//
//}
- (void)loginSuccess:(NSNotification*)notification {
UITableViewCell *cell = [self.menuView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
channelMenuLoginButton *loginBtn = (channelMenuLoginButton*)[cell viewWithTag:LOGINBTNTAG];
[loginBtn refreshLoginBtn];
[self refreshMsgMark];
}
- (void)loginOutSuccess:(NSNotification*)notification {
UITableViewCell *cell = [self.menuView cellForRowAtIndexPath:[NSIndexPath indexPathForRow:1 inSection:0]];
channelMenuLoginButton *loginBtn = (channelMenuLoginButton*)[cell viewWithTag:LOGINBTNTAG];
[loginBtn refreshLoginBtn];
[self refreshMsgMark];
}
- (void)needrefreshNightMode:(NSNotification*)noti {
isFromNoti = YES;
if ([[TPUserDefault instance].isNightMode intValue] == 1) {
[self changeNightMode:readModeBtn.button];
isFromNoti = NO;
}else {
[self changeDayMode:readModeBtn.button];
isFromNoti = NO;
}
}
@end
|