1.停止UIView动画的方法:
#import<QuartzCore/QuartzCore.h>
[self.view.layer removeAllAnimations];
2.block页面传值方法:
3.UITableViewCell中cell坐标转换
cell相对self.view的定位:
CGRect rect=[self.view convertRect:cell.frame fromView:tableView];
找到cell的相对位置后cell上button获取其他控件的相对位置都可以找出来
4.按文件创建时间排序
NSLog(@"cheng %@", cheng);
NSSortDescriptor*sorter=[[NSSortDescriptor alloc]initWithKey:@"createDate" ascending:NO];//降序
NSMutableArray *sortDescriptors=[[NSMutableArray alloc]initWithObjects:&sorter count:1];
NSArray *sortArray=[cheng sortedArrayUsingDescriptors:sortDescriptors];
[sorter release];
NSLog(@"then %@", sortArray);
5.IOS去文件后缀名
第一种方法:
NSArray *result = [fileName componentsSeparatedByString:@"."];
if(result.count != 2){
return ;
}
NSString *fileTitle = [result objectAtIndex:0];
NSString *fileType = [result objectAtIndex:1];
第二种方法:
NSString * fileName;//文件名
NSRange range = [sourceFile rangeOfString:@"." options:NSBackwardsSearch];
if (range.length>0)
fileName=[data.m_strTitle substringToIndex:NSMaxRange(range)];
第二种能够排除文件名字中带有.的情况
6.UIWebView 隐藏拖拽时上下阴影
//隐藏阴影
for (UIView *subView in [m_webView subviews])
{
if ([subView isKindOfClass:[UIScrollView class]])
{
for (UIView *shadowView in [subView subviews])
{
if ([shadowView isKindOfClass:[UIImageView class]])
{ shadowView.hidden = YES;
}
}
}
}
7.通过tag取cell上的控件
[cell.contentView viewWithTag:tag];
8.NSString 编码UTF8
//NSString 编码,解决url中空格和汉字
NSString * urlString= (NSString *)CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)urlStr, nil, nil,kCFStringEncodingUTF8);
9.iOS 获取本地视频的缩略图
+(UIImage *)getImage:(NSString *)videoURL
{
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:[NSURL fileURLWithPath:videoURL] options:nil];
AVAssetImageGenerator *gen = [[AVAssetImageGenerator alloc] initWithAsset:asset];
gen.appliesPreferredTrackTransform = YES;
CMTime time = CMTimeMakeWithSeconds(0.0, 600);
NSError *error = nil;
CMTime actualTime;
CGImageRef image = [gen copyCGImageAtTime:time actualTime:&actualTime error:&error];
UIImage *thumb = [[UIImage alloc] initWithCGImage:image];
CGImageRelease(image);
return thumb;
}
需要添加AVFoundation和CoreMedia.framework
10.验证图片有效性
- (BOOL)isJPEGValid:(NSData *)jpeg {
if ([jpeg length] < 4) return NO;
const char * bytes = (const char *)[jpeg bytes];
if (bytes[0] != 0xFF || bytes[1] != 0xD8) return NO;
if (bytes[[jpeg length] - 2] != 0xFF || bytes[[jpeg length] - 1] != 0xD9) return NO;
return YES;
}
11.UIButton标题对齐方式
m_btnCode.titleLabel.textAlignment=UITextAlignmentLeft;//没用
需要使用
[m_btnCode setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft];
12.ios 图片保存到相册
UIImageWriteToSavedPhotosAlbum是UIKit框架中的一个函数。
这里说一下后面三个参数的含义:
void UIImageWriteToSavedPhotosAlbum (
UIImage *image,
id completionTarget,
SEL completionSelector,
void *contextInfo
);
id是target对象,sel是selector,即target对象上的方法名,contextInfo是任意指针,会传递到selector定义的方法上。一般是当完成后调用方法时使用,或者在完成时出错的处理。
使用的时候:
UIImageWriteToSavedPhotosAlbum(m_currentImage.image, nil, nil, nil);//然后在相册中就能找到你添加的图片
13.ios 打开照片库,打开相机
//打开照片库
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
//imagePicker.allowsImageEditing = YES; //图片可以编辑
//需要添加委托
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
//打开相机
if([UIImagePickerControlle isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
//imagePicker.allowsImageEditing = YES;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:imagePicker animated:YES];
[imagePicker release];
}
13.CGRectOffset 的作用
相对于源矩形原点(左上角的点)沿x轴和y轴偏移 ,例如:
[self.view setFrame:CGRectOffset(self.view.frame, 260, 0)];
view沿着(0,0)x轴向右移动260个像素
14.数组深拷贝
NSMutableArray *arr1=[[NSMutableArray alloc] initWithObjects:@"a", @"b", @"c", nil];
NSMutableArray *arr2=[[NSMutableArray alloc] init];
arr2=[arr1 mutableCopy];
[arr1 removeObject:@"b"];
//结果arr1:a,c
//arr2:a,b,c
15.UITableViewCell 重用
解决在cell中添加其他控件时,滚动后重复加载,文字重影,控件错乱的情况
NSString *CellIdentifier = [NSString stringWithFormat:@"Cell%d%d", [indexPath section], [indexPath row]];
UITableViewCell *cell = [tableView dequeueReusableCellWi
补充:移动开发 , IOS ,