1获取系统语言设置
NSUserDefaults *userDefault = [NSUserDefaults standardUserDefaults];
NSArray *languages = [userDefault objectForKey:@"AppleLanguages"];
NSString *preferredLang = [languages objectAtIndex:0];
2缓存路径下文件大小
- (unsigned long long int) cacheFolderSize
{
NSFileManager *_manager = [NSFileManager defaultManager];
NSArray *_cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory,
NSUserDomainMask, YES);
NSString *_cacheDirectory = [_cachePaths objectAtIndex:];
NSArray *_cacheFileList;
NSEnumerator *_cacheEnumerator;
NSString *_cacheFilePath;
unsigned long long int _cacheFolderSize = ;
_cacheFileList = [ _manager subpathsAtPath:_cacheDirectory];
_cacheEnumerator = [_cacheFileList objectEnumerator];
while (_cacheFilePath = [_cacheEnumerator nextObject])
{
NSDictionary *_cacheFileAttributes = [_managerfileAttributesAtPath:
[_cacheDirectory stringByAppendingPathComponent:_cacheFilePath]
traverseLink:YES];
_cacheFolderSize += [_cacheFileAttributes fileSize];
}
// 单位是字节
return _cacheFolderSize;
}
3Popover
push 时 Frame无法改变解决办法在popover中的ViewController中实现:
- (void)viewWillAppear:(BOOL)animated
{
CGSize size = CGSizeMake(320, 480); // size of view in popover
self.contentSizeForViewInPopover = size;
[super viewWillAppear:animated];
}4tableview滑动导致NSTimer和委托回调停止解决办法
/ /请求回调
NSURLRequest * 请求 = ...
scheduleInRunLoop :[ NSRunLoop currentRunLoop ]
forMode :NSRunLoopCommonModes ]
[ 连接开始] / /定时器回调
NSTimer * updateTimer = [NSTimer scheduledTimerWithTimeInterval:0.01f目标:自我选择:选择(updatePencent)的UserInfo:无重复:是];
* NSRunLoop主要= [NSRunLoop currentRunLoop]
[主要addTimer:updateTimer forMode:NSRunLoopCommonModes];
5手势识别类
UIGestureRecognizer
6SFHFKeychainUtils
存储信息
苹果SDK自带的就有密码保护,使用方法很简单,如下:
1、引入Security.frameWork框架。
2、引入头文件:SFHKeychainUtils.h.
3、存密码:
[SFHFKeychainUtils storeUsername:@"dd" andPassword:@"aa"forServiceName:SERVICE_NAMEupdateExisting:1 error:nil];
[SFHFKeychainUtils deleteItemForUsername:@"dd" andServiceName:SERVICE_NAME error:nil];
4、取密码:
NSString *passWord = [SFHFKeychainUtils getPasswordForUsername:@"dd"andServiceName:SERVICE_NAMEerror:nil];
7missing
required architecture i386 in file 解决办法
在TargetInfo里面修改 Framework Search Pasths 删除里面内容就可以了。
8view
放大缩小动画效果
//创建缩小了的视图
myWeiBoImageVC = [[UIViewController alloc] init];
myWeiBoImageVC.view.clipsToBounds = YES;
myWeiBoImageVC.view.alpha = 0.0;
myWeiBoImageVC.view.frame = CGRectMake(64, 0, 1024-64, 768-20);
[self.view addSubview:myWeiBoImageVC.view];
CGAffineTransform newTransform =
CGAffineTransformScale(myWeiBoImageVC.view.transform, 0.1, 0.1);
[myWeiBoImageVC.view setTransform:newTransform];
myWeiBoImageVC.view.center = CGPointMake(670, 100);
[self performSelector:@selector(imageViewControllerBigAnimation)];
//放大刚刚创建缩小后的视图
- (void)imageViewControllerBigAnimation{
[UIView beginAnimations:@"imageViewBig" context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform newTransform = CGAffineTransformConcat(myWeiBoImageVC.view.transform, CGAffineTransformInvert(myWeiBoImageVC.view.transform));
[myWeiBoImageVC.view setTransform:newTransform];
myWeiBoImageVC.view.alpha = 1.0;
myWeiBoImageVC.view.center = CGPointMake(416, 510);
[UIView commitAnimations];
}
//缩小视图 隐藏
- (void)imageViewControllerSmallAnimation{
[UIView beginAnimations:@"imageViewSmall" context:nil];
[UIView setAnimationDuration:0.5];
CGAffineTransform newTransform = CGAffineTransformScale(myWeiBoImageVC.view.transform, 0.1, 0.1);
[myWeiBoImageVC.view setTransform:newTransform];
myWeiBoImageVC.view.center = CGPointMake(670, 100);
[UIView commitAnimations];
}
9UIScrollView
控制View缩放
allImageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 768, 1024)];
allImageScrollView.minimumZoomScale = 0.3;
allImageScrollView.maximumZoomScale = 1.0;
allImageScrollView.backgroundColor = [UIColor clearColor];
allImageScrollView.delegate = self;
[self.view addSubview:allImageScrollView];
mPicStatusesViewController = [[PicStatusesViewController alloc] init];
[allImageScrollView addSubview:mPicStatusesViewController.view];
//UIScrollView Delegete 实现
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return mPicStatusesViewController.view; //返回ScrollView上添加的需要缩放的视图
}
- (void)scrollViewDidZoom:(UIScrollView *)scrollView
{
//缩放操作中被调用
}
- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView withView:(UIView *)view atScale:(float)scale
{
//缩放结束后被调用
}
10iOS3.2
播放视频
NSString *urlString = [NSString stringWithString:@"视频url"];
NSURL *movieUrl = [[NSURL alloc] initWithString:urlString];
MPMoviePlayerController *myMoviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
myMoviePlayer.view.frame = CGRectMake(250, 250, 350, 350);
[self.view addSubview:myMoviePlayer.view];
myMoviePlayer.shouldAutoplay = YES;
myMoviePlayer.scalingMode= MPMovieScalingModeAspectFit;
[myMoviePlayer play];