1 禁止侧滑
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = NO;
}
在其他离开改页面的方法同样加上下面代码
if([self.navigationController respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.navigationController.interactivePopGestureRecognizer.enabled = YES;
}
2 pch路径
$(SRCROOT)/$(PRODUCT_NAME)/PrefixHeader.pch
3 阿拉伯数字和汉字相互转化:
http://www.jianshu.com/p/aa2873d72a51
4 设置半圆角
UIBezierPath * codePath = [UIBezierPath bezierPathWithRoundedRect:_codeBtn.bounds byRoundingCorners:UIRectCornerTopRight | UIRectCornerBottomRight cornerRadii:CGSizeMake(5,5)];
CAShapeLayer*maskLayer = [[CAShapeLayer alloc]init];
maskLayer.frame = _codeBtn.bounds;
maskLayer.path = codePath.CGPath;
_codeBtn.layer.mask = maskLayer;
5 tableview实用小方法
http://blog.csdn.net/daiyelang/article/details/39076317
6 定时器实用小方法
创建定时器:
NSTimer * timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerRun) userInfo:nil repeats:YES];
开启定时器:
[timer setFireDate:[NSDate distantPast]];
关闭定时器:
[timer setFireDate:[NSDate distantFuture]];
摧毁定时器:
[timer invalidate];
timer = nil;
7 秒数—>时分秒
//转换成时分秒
- (NSString *)timeFormatted:(int)totalSeconds
{
int seconds = totalSeconds % 60;
int minutes = (totalSeconds / 60) % 60;
int hours = totalSeconds / 3600;
return [NSString stringWithFormat:@"%02d:%02d:%02d",hours, minutes, seconds];
}
8 距离当前时间N秒的时间值
//转换成当前时刻
- (NSString *)timeFormatted:(int)totalSeconds
{
NSDate *date = [NSDate dateWithTimeIntervalSince1970:totalSeconds];
NSTimeZone *zone = [NSTimeZone systemTimeZone];
NSInteger interval = [zone secondsFromGMTForDate: date];
NSDate *localeDate = [date dateByAddingTimeInterval: interval];
NSLog(@"enddate=%@",localeDate);
}
9 加载gif图
1,创建YYAnimatedImageView对象
YYAnimatedImageView *imageView=[YYAnimatedImageView new];
(1)直接通过url加载:
NSURL *path = [[NSBundle mainBundle]URLForResource:@"guidegif" withExtension:@"gif"];
imageView.yy_imageURL = path;
(2)通过YYImage加载:
NSURL *path = [[NSBundle mainBundle]URLForResource:@"guidegif_loop" withExtension:@"gif"];
YYImage * image = [YYImage imageWithContentsOfFile:path.path];
imageView.image = image;
10 计算连续签到天数
- (NSInteger)calculateDays
{
NSInteger days = 0;
NSString *dayStr = [GetUserInfoModel getUesrInfoModel].sign_days;
// dayStr = @"20170524,20170526,20170527,20170529,20170530,20170530";
NSArray *array = [dayStr componentsSeparatedByString:@","];
if (array.count>0)
{
//将数组中的字符串转换为时间格式
NSMutableArray * newArr = [NSMutableArray arrayWithArray:array];
for (int i = 0; i<newArr.count; i++)
{
NSString * string = newArr[i];
NSDateFormatter * formatter = [[NSDateFormatter alloc]init];
[formatter setDateFormat:@"YYYYMMdd"];
NSDate * strDate = [formatter dateFromString:string];
[newArr replaceObjectAtIndex:i withObject:strDate];
}
NSDate * lastDate = [newArr lastObject];
//判断今天是否打卡
if ([self getDaysFrom:lastDate To:[NSDate date]] != 0)
{
//今天未打卡
NSDate * yesDate = [NSDate dateWithTimeInterval:-24*60*60 sinceDate:[NSDate date]];//前一天
if ([self getDaysFrom:yesDate To:[newArr lastObject]] == 0)
{
days = 1;
for (NSInteger i = newArr.count-2; i>=0; i--)
{
NSDate * endDate = newArr[i+1];
NSDate * lastDate = newArr[i];
if ([self getDaysFrom:lastDate To:endDate] == 1)
{
days++;
}
else if ([self getDaysFrom:lastDate To:endDate] == 0)
{
}
else
{
break;
}
}
}
}
else
{
//今天已打过卡
days = 1;
NSDate * endDate = [NSDate date];
for (NSInteger i = newArr.count-1; i>=0; i--)
{
NSDate * lastDate = newArr[i];
if ([self getDaysFrom:lastDate To:endDate] == 1)
{
days++;
}
else if ([self getDaysFrom:lastDate To:endDate] == 0)
{
}
else
{
break;
}
endDate = newArr[i];
}
}
}
NSLog(@"连续打卡天数====%ld",(long)days);
return days;
}