You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
573 lines
21 KiB
573 lines
21 KiB
// |
|
// TrackViewController.m |
|
// LekangGuard |
|
// |
|
// Created by ecell on 2022/12/14. |
|
// |
|
|
|
#import "TrackViewController.h" |
|
#import "VRGCalendarView.h" |
|
#import "TrackTableViewCell.h" |
|
#import "TrackMapView.h" |
|
|
|
@interface TrackViewController ()<DZNEmptyDataSetSource,DZNEmptyDataSetDelegate,VRGCalendarViewDelegate,UITableViewDelegate,UITableViewDataSource> |
|
|
|
@property (nonatomic ,strong) UITableView *comTable; |
|
|
|
@property (strong, nonatomic) VRGCalendarView *calendar; |
|
|
|
@property (strong, nonatomic) UIControl *overlayView; |
|
|
|
/// 顶部View |
|
@property (nonatomic ,strong) UIView *topView; |
|
|
|
/// 后一天 |
|
@property (weak, nonatomic) UIButton *afterDayBtn; |
|
|
|
/// 前一天 |
|
@property (weak, nonatomic) UIButton *beforeDayBtn; |
|
|
|
/// 时间显示Btn |
|
@property (weak, nonatomic) UIButton *dayTimeBtn; |
|
|
|
@property (nonatomic ,strong) UIView *headerView; |
|
|
|
/// 轨迹条数显示 |
|
@property (nonatomic ,weak) UILabel *numberLabel; |
|
|
|
/// 轨迹地图 |
|
@property (nonatomic ,strong) TrackMapView *trackMapView; |
|
|
|
@end |
|
|
|
@implementation TrackViewController |
|
|
|
- (void)viewDidLoad { |
|
[super viewDidLoad]; |
|
// Do any additional setup after loading the view. |
|
self.zx_navTitle = GJText(@"历史轨迹"); |
|
self.ImgType = Lishijilu; |
|
self.emptyText = GJText(@"没有历史数据"); |
|
[self zx_setRightBtnWithText:GJText(@"地图查看") clickedBlock:^(ZXNavItemBtn * _Nonnull btn) { |
|
btn.selected = !btn.selected; |
|
[btn setTitle:GJText(@"地图查看") forState:UIControlStateNormal]; |
|
[btn setTitle:GJText(@"轨迹查看") forState:UIControlStateSelected]; |
|
[self mapShowAndHidden:btn.selected ? 1 : 0]; |
|
}]; |
|
self.zx_navRightBtn.hidden = YES; |
|
|
|
[self.view addSubview:self.comTable]; |
|
[self.comTable mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.right.equalTo(self.view); |
|
make.top.equalTo(self.view).offset(iPhoneX_NavHeight+Adapted(50)+0.5); |
|
make.bottom.equalTo(self.view.mas_bottom); |
|
}]; |
|
[self.view addSubview:self.trackMapView]; |
|
[self.view addSubview:self.topView]; |
|
[self GetTrackInfo]; |
|
|
|
} |
|
|
|
|
|
- (UITableView *)comTable |
|
{ |
|
if (!_comTable) |
|
{ |
|
_comTable = [[UITableView alloc] init]; |
|
_comTable.delegate = self; |
|
_comTable.dataSource = self; |
|
_comTable.emptyDataSetSource = self; |
|
_comTable.emptyDataSetDelegate = self; |
|
_comTable.backgroundColor = KKClearColor; |
|
_comTable.separatorStyle = UITableViewCellSeparatorStyleNone; |
|
[_comTable registerClass:TrackTableViewCell.class forCellReuseIdentifier:NSStringFromClass(TrackTableViewCell.class)]; |
|
} |
|
return _comTable; |
|
} |
|
|
|
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ |
|
return self.modelListArr.count; |
|
} |
|
|
|
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ |
|
|
|
TrackInfoModel *model = self.modelListArr[indexPath.row]; |
|
CGRect rect = [UICommon GetTextWidth:model.addr ViewHeight:SCREEN_WIDTH-105 fontSize:Font_(15) type:@"h"]; |
|
CGFloat hh = 12.5+rect.size.height+15+Adapted(18)+8; |
|
return hh; |
|
} |
|
|
|
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath |
|
{ |
|
TrackTableViewCell *cell = [TrackTableViewCell cellWithTableView:tableView indexPath:indexPath]; |
|
TrackInfoModel *model = self.modelListArr[indexPath.row]; |
|
CGRect rect = [UICommon GetTextWidth:model.addr ViewHeight:SCREEN_WIDTH-105 fontSize:Font_(15) type:@"h"]; |
|
CGFloat hh = 12.5+rect.size.height+15+Adapted(18)+8; |
|
NSInteger rows = 1; |
|
if (self.modelListArr.count == 1) |
|
rows = 0; |
|
else |
|
{ |
|
if (indexPath.row == 0) |
|
rows = 0; |
|
else if (indexPath.row == self.modelListArr.count-1) |
|
rows = 2; |
|
} |
|
|
|
NSString *dateStr = [UICommon getDateFormatWithStr:@"HH:mm" |
|
date:[NSDate dateWithTimeIntervalSince1970:[self getTimeStrWithString:model.createTime]]]; |
|
|
|
NSString *stayTime = [self secondToTime:model.residenceTime]; |
|
[cell setIconType:rows WithAddress:model.addr WithTime:dateStr CanShapeToView:self.modelListArr.count == 1 ? NO : YES StayTime:stayTime ViewHeight:hh]; |
|
return cell; |
|
} |
|
|
|
|
|
|
|
#pragma mark 轨迹地图View |
|
/// 轨迹地图View |
|
- (TrackMapView *)trackMapView |
|
{ |
|
if (!_trackMapView) |
|
{ |
|
CGFloat yy = iPhoneX_NavHeight+Adapted(50)+0.5; |
|
_trackMapView = [[TrackMapView alloc] initWithFrame:CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-yy)]; |
|
} |
|
return _trackMapView; |
|
} |
|
|
|
- (void)mapShowAndHidden:(NSInteger)type |
|
{ |
|
CGFloat yy = iPhoneX_NavHeight+self.topView.height+0.5; |
|
[UIView animateWithDuration:0.5 animations:^{ |
|
self.trackMapView.frame = CGRectMake(0,type == 1 ? yy : SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT-yy); |
|
} completion:^(BOOL finished) { |
|
[self.trackMapView topViewShowAndHidden:type]; |
|
}]; |
|
} |
|
|
|
|
|
|
|
#pragma mark 查询轨迹信息 |
|
/// 查询轨迹信息 |
|
- (void)GetTrackInfo |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[parameters setValue:APIManager.sharedManager.deviceModel.imei forKey:@"imei"]; |
|
[parameters setValue:[self timeConversion] forKey:@"startTime"]; |
|
[[[APIManager sharedManager] APPOST:TrackInfo_URL parameters:parameters isJson:YES resultClass:nil] subscribeNext:^(NSArray *arr) { |
|
[UICommon HidenLoading]; |
|
[self.modelListArr removeAllObjects]; |
|
if (ARRAYHASVALUE(arr)) |
|
{ |
|
for (NSDictionary *dic in arr) |
|
{ |
|
TrackInfoModel *model = [TrackInfoModel yy_modelWithJSON:dic]; |
|
[self.modelListArr addObject:model]; |
|
} |
|
} |
|
self.comTable.tableHeaderView = arr.count > 0 ? self.headerView : nil; |
|
self.comTable.tableHeaderView.height = arr.count > 0 ? Adapted(60) : 0; |
|
self.numberLabel.attributedText = [UICommon labelFontSize:arr.count > 0 ? F(@"%ld %@", arr.count,GJText(@"条轨迹")) : @""]; |
|
[self.trackMapView loadWithInfoTrack:self.modelListArr]; |
|
|
|
[self.comTable reloadData]; |
|
self.zx_navRightBtn.hidden = self.modelListArr.count > 0 ? NO : YES; |
|
if (self.modelListArr.count <= 0) |
|
{ |
|
self.zx_navRightBtn.selected = NO; |
|
[self mapShowAndHidden:0]; |
|
} |
|
|
|
|
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
|
|
#pragma mark 根据日期删除轨迹信息 |
|
/// 根据日期删除轨迹信息 |
|
- (void)deleteTrackInfo |
|
{ |
|
[UICommon MessageUpload:@"加载中"]; |
|
NSMutableDictionary *parameters = [NSMutableDictionary dictionary]; |
|
[[[APIManager sharedManager] APDELETE:F(@"%@/%@/%@", DeleteTrackInfo_URL,APIManager.sharedManager.deviceModel.imei,[self timeConversion]) parameters:parameters resultClass:nil] subscribeNext:^(id _Nullable x) { |
|
[UICommon HidenLoading]; |
|
[UICommon MessageSuccessText:@"删除成功"]; |
|
[self GetTrackInfo]; |
|
} error:^(NSError * _Nullable error) { |
|
NSDictionary *dic = error.userInfo; |
|
[UICommon MessageErrorText:dic[NSLocalizedDescriptionKey]]; |
|
}]; |
|
} |
|
|
|
#pragma mark 顶部时间选择View |
|
/// 顶部时间选择View |
|
- (UIView *)topView |
|
{ |
|
if (!_topView) |
|
{ |
|
_topView = [UIView new]; |
|
_topView.backgroundColor = KKWhiteColorColor; |
|
_topView.frame = CGRectMake(0, iPhoneX_NavHeight, SCREEN_WIDTH, Adapted(50)); |
|
/// 前一天 |
|
UIButton *beforeDayBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKWhiteColorColor normalText:GJText(@"前一天") click:^(id x) { |
|
[self dayBtnAction:1]; |
|
}]; |
|
|
|
CGRect rect1 = [UICommon GetTextWidth:beforeDayBtn.currentTitle ViewHeight:Adapted(25) fontSize:FontADA_(14) type:@"w"]; |
|
beforeDayBtn.backgroundColor = KKMainColor; |
|
beforeDayBtn.layer.cornerRadius = 5; |
|
beforeDayBtn.layer.masksToBounds = YES; |
|
self.beforeDayBtn = beforeDayBtn; |
|
[_topView addSubview:beforeDayBtn]; |
|
[beforeDayBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.left.equalTo(_topView).offset(20); |
|
make.centerY.equalTo(_topView); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(rect1.size.width+10), Adapted(25))); |
|
}]; |
|
|
|
/// 后一天 |
|
UIButton *afterDayBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(14) normalColor:KKWhiteColorColor normalText:GJText(@"后一天") click:^(id x) { |
|
[self dayBtnAction:2]; |
|
}]; |
|
CGRect rect = [UICommon GetTextWidth:afterDayBtn.currentTitle ViewHeight:Adapted(25) fontSize:FontADA_(14) type:@"w"]; |
|
afterDayBtn.backgroundColor = KKMainColor; |
|
afterDayBtn.layer.cornerRadius = 5; |
|
afterDayBtn.layer.masksToBounds = YES; |
|
self.afterDayBtn = afterDayBtn; |
|
[_topView addSubview:afterDayBtn]; |
|
[afterDayBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(_topView.mas_right).inset(20); |
|
make.centerY.equalTo(_topView); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(rect.size.width+10), Adapted(25))); |
|
}]; |
|
|
|
/// 中间显示当前时间 |
|
UIButton *dayTimeBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(16) normalColor:KKMainColor normalText:@"" click:^(id x) { |
|
[self dayTimeBtnAction]; |
|
}]; |
|
[dayTimeBtn setImage:ImageName_(@"icon_drop-down") forState:0]; |
|
self.dayTimeBtn = dayTimeBtn; |
|
[_topView addSubview:dayTimeBtn]; |
|
[dayTimeBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.centerX.equalTo(_topView); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(100), Adapted(34))); |
|
}]; |
|
[self setDayTimeLabelText:GJText(@"今天")]; |
|
|
|
} |
|
return _topView; |
|
} |
|
|
|
|
|
#pragma mark 当前时间按钮点击方法 |
|
/// 当前时间按钮点击方法 |
|
- (void)dayTimeBtnAction |
|
{ |
|
[self dismissCalendarView]; |
|
self.overlayView = [[UIControl alloc]initWithFrame:CGRectMake(0, iPhoneX_NavHeight, SCREEN_WIDTH, SCREEN_HEIGHT-iPhoneX_NavHeight)]; |
|
[_overlayView addTarget:self action:@selector(dismissCalendarView) forControlEvents:UIControlEventTouchUpInside]; |
|
self.calendar = [[VRGCalendarView alloc] init]; |
|
self.calendar.limitDay = 60; |
|
CGRect c = self.calendar.frame; |
|
c.origin.y = iPhoneX_NavHeight+Adapted(50); |
|
self.calendar.frame = c; |
|
self.calendar.delegate = self; |
|
|
|
NSDate *selectDate; |
|
if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"今天")]) |
|
{ |
|
//今天 |
|
selectDate = [NSDate dateWithTimeIntervalSince1970:[NSDate date].timeIntervalSince1970]; |
|
} |
|
else if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"昨天")]) |
|
{ |
|
//昨天 |
|
selectDate = [NSDate dateWithTimeIntervalSince1970:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
} |
|
else |
|
{ |
|
NSDateFormatter * dateF = [[NSDateFormatter alloc]init]; |
|
[dateF setCalendar:[[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]]; |
|
[dateF setDateFormat:@"yyyy-MM-dd"]; |
|
NSDate *date =[dateF dateFromString:self.dayTimeBtn.titleLabel.text]; |
|
selectDate = date; |
|
} |
|
//今天 |
|
// selectDate = [NSDate dateWithTimeIntervalSince1970:[NSDate date].timeIntervalSince1970]; |
|
self.calendar.selectedDate = selectDate; |
|
|
|
self.calendar.alpha = 1; |
|
[self.view addSubview:_overlayView]; |
|
[self.view addSubview:self.calendar]; |
|
} |
|
|
|
- (void)dismissCalendarView |
|
{ |
|
if(_overlayView) |
|
{ |
|
[_overlayView removeFromSuperview]; |
|
_overlayView = nil; |
|
[UIView animateWithDuration:0.35 animations:^{ |
|
self.calendar.alpha = 0; |
|
}completion:^(BOOL finished) { |
|
[self.calendar removeFromSuperview]; |
|
}]; |
|
//[self.dayTimeIconBtn setImage:[UIImage imageNamed:@"icon_drop-down"] forState:0]; |
|
} |
|
} |
|
#pragma mark - 日期选择Delegate |
|
-(void)calendarView:(VRGCalendarView *)calendarView switchedToMonth:(int)month targetHeight:(float)targetHeight animated:(BOOL)animated |
|
{ |
|
|
|
} |
|
|
|
-(void)calendarView:(VRGCalendarView *)calendarView dateSelected:(NSDate *)date |
|
{ |
|
NSString *selectDay = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" date:date]; |
|
//对比昨天和今天 |
|
//昨天 |
|
NSString *yesterday = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
//今天 |
|
NSString *today = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970]; |
|
if([selectDay isEqualToString:yesterday]) |
|
{ |
|
[self setDayTimeLabelText:GJText(@"昨天")]; |
|
|
|
}else if([selectDay isEqualToString:today]) |
|
{ |
|
[self setDayTimeLabelText:GJText(@"今天")]; |
|
} |
|
else |
|
{ |
|
[self setDayTimeLabelText:selectDay]; |
|
} |
|
|
|
[self GetTrackInfo]; |
|
[self dismissCalendarView]; |
|
} |
|
|
|
-(void)setDayTimeLabelText:(NSString*)day |
|
{ |
|
[self.dayTimeBtn setTitle:day forState:0]; |
|
CGRect rect = [UICommon GetTextWidth:day ViewHeight:Adapted(34) fontSize:FontADA_(16) type:@"w"]; |
|
CGFloat spacing = 5; |
|
[self.dayTimeBtn setImageEdgeInsets:UIEdgeInsetsMake(0, rect.size.width + spacing/2, 0, -(rect.size.width + spacing/2))]; |
|
[self.dayTimeBtn setTitleEdgeInsets:UIEdgeInsetsMake(0, -(self.dayTimeBtn.currentImage.size.width + spacing/2), 0, self.dayTimeBtn.currentImage.size.width + spacing/2)]; |
|
} |
|
|
|
#pragma mark 前一天或者后一天按钮点击方法 |
|
/// 前一天或者后一天按钮点击方法 |
|
- (void)dayBtnAction:(NSInteger)type |
|
{ |
|
// if(self.isLoading){ |
|
// return; |
|
// } |
|
// self.isLoading = YES; |
|
NSMutableDictionary * params = [NSMutableDictionary dictionary]; |
|
|
|
if(type == 1) |
|
{ //按了前一天的按钮 |
|
NSString *paramsDay; |
|
if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"今天")]) |
|
{ |
|
//昨天 |
|
paramsDay = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
[self setDayTimeLabelText:GJText(@"昨天")]; |
|
} |
|
else if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"昨天")]) |
|
{ |
|
paramsDay = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 2 * 60*60*24]; |
|
[self setDayTimeLabelText: paramsDay]; |
|
} |
|
else |
|
{ |
|
//当前位置的天数转换成的时间戳 |
|
NSTimeInterval tempTime = [UICommon getDateWithStr:self.dayTimeBtn.titleLabel.text dateFormat:@"yyyy-MM-dd"].timeIntervalSince1970; |
|
paramsDay = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:tempTime - 60*60*24]; |
|
[self setDayTimeLabelText: paramsDay]; |
|
} |
|
[params setValue:paramsDay forKey:@"date"]; |
|
|
|
} |
|
else if(type == 2) |
|
{ |
|
if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"今天")]) |
|
return; |
|
//后一天 |
|
if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"昨天")]) |
|
{ |
|
[self setDayTimeLabelText:GJText(@"今天")]; |
|
params = nil; |
|
} |
|
else |
|
{ |
|
//当前位置的天数转换成的时间戳 |
|
NSTimeInterval tempTime = [UICommon getDateWithStr:self.dayTimeBtn.titleLabel.text dateFormat:@"yyyy-MM-dd"].timeIntervalSince1970; |
|
NSString *paramsDay = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:tempTime + 60*60*24]; |
|
//对比昨天和今天 |
|
//昨天 |
|
NSString *yesterday = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
//今天 |
|
NSString *today = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970]; |
|
if([paramsDay isEqualToString:yesterday]) |
|
{ |
|
[self setDayTimeLabelText:GJText(@"昨天")]; |
|
|
|
}else if([paramsDay isEqualToString:today]) |
|
{ |
|
[self setDayTimeLabelText:GJText(@"今天")]; |
|
} |
|
else |
|
{ |
|
[self setDayTimeLabelText:paramsDay]; |
|
} |
|
[params setValue:paramsDay forKey:@"date"]; |
|
} |
|
|
|
} |
|
else |
|
{ |
|
params = nil; |
|
} |
|
|
|
[self GetTrackInfo]; |
|
} |
|
|
|
#pragma mark 轨迹列表头部信息 |
|
/// 轨迹列表头部信息 |
|
- (UIView *)headerView |
|
{ |
|
if(!_headerView) |
|
{ |
|
_headerView = [UIView new]; |
|
_headerView.backgroundColor = KKClearColor; |
|
_headerView.frame = CGRectMake(0, 0, SCREEN_WIDTH, Adapted(60)); |
|
|
|
UIImageView *iconImg = [UIImageView new]; |
|
iconImg.image = APIManager.sharedManager.deviceModel.sex == 1 ? ImageName_(@"icon_head_boy") : ImageName_(@"icon_head_girl"); |
|
if (APIManager.sharedManager.deviceModel.image.length > 0) |
|
[iconImg sd_setImageWithURL:[NSURL URLWithString:APIManager.sharedManager.deviceModel.image]]; |
|
iconImg.layer.cornerRadius = Adapted(20); |
|
iconImg.layer.masksToBounds = YES; |
|
[_headerView addSubview:iconImg]; |
|
[iconImg mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.equalTo(_headerView); |
|
make.left.equalTo(_headerView).offset(30); |
|
make.size.mas_equalTo(CGSizeMake(Adapted(40), Adapted(40))); |
|
}]; |
|
|
|
UILabel *numberLabel = [UICommon ui_label:CGRectZero lines:0 align:NSTextAlignmentCenter font:FontBoldADA_(30) textColor:KKMainColor text:@"" Radius:0]; |
|
self.numberLabel = numberLabel; |
|
[_headerView addSubview:numberLabel]; |
|
[numberLabel mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.centerY.centerX.equalTo(_headerView); |
|
}]; |
|
|
|
UIButton *deleteBtn = [UICommon ui_buttonSimple:CGRectZero font:FontADA_(0) normalColor:KKWhiteColorColor normalText:@"" click:^(id x) { |
|
[self deleteTrackInfo]; |
|
}]; |
|
[deleteBtn setImage:ImageName_(@"icon_delect_black") forState:0]; |
|
[_headerView addSubview:deleteBtn]; |
|
[deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) { |
|
make.right.equalTo(_headerView.mas_right).inset(25); |
|
make.centerY.equalTo(_headerView); |
|
make.size.mas_equalTo(CGSizeMake(AdaptedHeight(deleteBtn.currentImage.size.width), AdaptedHeight(deleteBtn.currentImage.size.height))); |
|
}]; |
|
|
|
} |
|
return _headerView; |
|
} |
|
|
|
/** |
|
设置按钮不可选且半透明 |
|
@param flag Bad is NO , Good is YES |
|
@param button button |
|
*/ |
|
-(void)setBtnBadRoGoodFlag:(BOOL)flag WithBtn:(id) button{ |
|
if(flag){ |
|
if([button isKindOfClass:[UIButton class]]){ |
|
[button setAlpha:1]; |
|
} |
|
[button setEnabled:YES]; |
|
}else{ |
|
if([button isKindOfClass:[UIButton class]]){ |
|
[button setAlpha:0.5]; |
|
} |
|
[button setEnabled:NO]; |
|
} |
|
} |
|
|
|
- (NSString *)secondToTime:(long)seconds |
|
{ |
|
|
|
long days = seconds/86400; |
|
seconds = seconds%86400; |
|
|
|
long hours = seconds/3600; |
|
seconds = seconds%3600; |
|
|
|
long minutes = ceil(seconds/60.0); |
|
seconds = seconds%60; |
|
|
|
if (days > 0) { |
|
return [NSString stringWithFormat:@"停留%zd天%zd小时%zd分",days,hours,minutes]; |
|
} else if (hours > 0) { |
|
return [NSString stringWithFormat:@"停留%zd小时%zd分",hours,minutes]; |
|
} else if(minutes > 0) { |
|
return [NSString stringWithFormat:@"停留%zd分",minutes]; |
|
} else { |
|
return @"0"; |
|
} |
|
} |
|
|
|
#pragma mark 获取当前选中时间 |
|
/// 获取当前选中时间 |
|
- (NSString *)timeConversion |
|
{ |
|
NSString *currenDateStr = @""; |
|
if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"今天")]) |
|
{ |
|
NSString *today = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970]; |
|
currenDateStr = today; |
|
[self setBtnBadRoGoodFlag:NO WithBtn:self.afterDayBtn]; |
|
} |
|
else if([self.dayTimeBtn.currentTitle isEqualToString:GJText(@"昨天")]) |
|
{ |
|
NSString *yesterday = [UICommon getDateFormatWithStr:@"yyyy-MM-dd" timeInterval:[NSDate date].timeIntervalSince1970 - 60*60*24]; |
|
currenDateStr = yesterday; |
|
[self setBtnBadRoGoodFlag:YES WithBtn:self.afterDayBtn]; |
|
} |
|
else |
|
{ |
|
currenDateStr = self.dayTimeBtn.titleLabel.text; |
|
[self setBtnBadRoGoodFlag:YES WithBtn:self.afterDayBtn]; |
|
} |
|
return currenDateStr; |
|
} |
|
|
|
- (NSInteger)getTimeStrWithString:(NSString*)str |
|
{ |
|
NSDateFormatter*dateFormatter=[[NSDateFormatter alloc]init];// 创建一个时间格式化对象 |
|
[dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"]; |
|
//设定时间的格式 |
|
NSDate*tempDate = [dateFormatter dateFromString:str];//将字符串转换为时间对象 |
|
NSInteger timeStr = [tempDate timeIntervalSince1970];//字符串转成时间戳,精确到毫秒*1000returntimeStr; |
|
return timeStr; |
|
} |
|
|
|
/* |
|
#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
|
|
|