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 阿拉伯數(shù)字和漢字相互轉化:
http://www.reibang.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 定時器實用小方法
創(chuàng)建定時器:
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 秒數(shù)—>時分秒
//轉換成時分秒
- (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媚媒,創(chuàng)建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 計算連續(xù)簽到天數(shù)
- (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)
{
//將數(shù)組中的字符串轉換為時間格式
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(@"連續(xù)打卡天數(shù)====%ld",(long)days);
return days;
}