杂七杂八
2016-08-31 本文已影响14人
音吹
NS_REQUIRES_NIL_TERMINATION
<code>titles:(NSString *)firstTitle, ... NS_REQUIRES_NIL_TERMINATION</code>
列表foot和header不滑动
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat sectionHeaderHeight = 40;
if (scrollView.contentOffset.y<=sectionHeaderHeight&&scrollView.contentOffset.y>=0) {
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
}else if (scrollView.contentOffset.y>=sectionHeaderHeight) {
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
}
}
剪裁图片尺寸
- (UIImage *)scaleFromImage:(UIImage *)image toSize:(CGSize)size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage * newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
时间戳
//时间戳 转成 时间
- (NSString *)dateTo:(NSString *)str
{
NSTimeInterval time=[str integerValue];
NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
//设定时间格式,这里可以设置成自己需要的格式
[dateFormatter setDateFormat:@"yyyy-MM-dd"];
NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
return currentDateStr;
}
//时间 转成 时间戳
- (NSString *)dateFromString:(NSString *)dateString{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat: @"yyyy-MM-dd"];
NSDate *destDate= [dateFormatter dateFromString:dateString];
NSString * timeSp = [NSString stringWithFormat:@"%ld",(long)[destDate timeIntervalSince1970]];
return timeSp;
}
获取视频封面图片
- (UIImage *)thumbnailImageForVideo:(NSURL *)videoURL atTime:(NSTimeInterval)time{
AVURLAsset * asset = [[AVURLAsset alloc] initWithURL:videoURL options:nil];
NSParameterAssert(asset);
AVAssetImageGenerator * assetImageGenerator = [[AVAssetImageGenerator alloc] initWithAsset:asset];
assetImageGenerator.appliesPreferredTrackTransform = YES;
assetImageGenerator.apertureMode =AVAssetImageGeneratorApertureModeEncodedPixels;
CGImageRef thumnailImageRef = NULL;
CFTimeInterval thumnailImageTime = time;
NSError * thumnailImageGenerationError = nil;
thumnailImageRef = [assetImageGenerator copyCGImageAtTime:CMTimeMake(thumnailImageTime, 60) actualTime:NULL error:&thumnailImageGenerationError];
if (!thumnailImageRef) {
NSLog(@"%@",thumnailImageGenerationError);
}
UIImage * thumbnailImage = thumnailImageRef?[[UIImage alloc] initWithCGImage:thumnailImageRef]:nil;
return thumbnailImage;
}
书名
NSString *dbPath = [NSHomeDirectory() stringByAppendingString:@"/Documents"];
NSDirectoryEnumerator *enumerator = [[NSFileManager defaultManager]enumeratorAtPath:dbPath];
for (NSString *fileName in enumerator)
{
NSLog(@"书名: %@",fileName);
}