当前位置:编程学习 > wap >>

IOS_月薪10k以上知识大总结

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

{
    //缩放结束后被调用
  }

10、iOS3.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];


11、谷歌地图翻起动画效果

    CATransition *animation = [CATransition animation];
    [animation setDelegate:self];
    [animation setDuration:0.35];
    [animation setTimingFunction:UIViewAnimationCurveEaseInOut];
    if (!curled){

        animation.type = @"pageCurl";
        animation.fillMode = kCAFillModeForwards;
        animation.endProgress = 0.40;
    } else {
        animation.type = @"pageUnCurl";
        animation.fillMode = kCAFillModeBackwards;
        animation.startProgress = 0.30;
    }
    [animation setRemovedOnCompletion:NO];
    [self.view exchangeSubviewAtIndex:0 withSubviewAtIndex:1];
    
    [self.view.layer addAnimation:animation forKey:@"pageCurlAnimation"];

12、给View添加阴影 和边框

UIImageView *imgvPhoto  = [UIImageView alloc] init];

//添加边框
   CALayer *layer = [_imgvPhoto layer];
    layer.borderColor = [[UIColor whiteColor] CGColor];
    layer.borderWidth = 5.0f;
//添加四个边阴影
    _imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
    _imgvPhoto.layer.shadowOffset = CGSizeMake(0, 0);
    _imgvPhoto.layer.shadowOpacity = 0.5;
    _imgvPhoto.layer.shadowRadius = 10.0;
//添加两个边阴影
    _imgvPhoto.layer.shadowColor = [UIColor blackColor].CGColor;
    _imgvPhoto.layer.shadowOffset = CGSizeMake(4, 4);
    _imgvPhoto.layer.shadowOpacity = 0.5;
    _imgvPhoto.layer.shadowRadius = 2.0;

13、使用NSTimer与UIView动画实现飘雪效果

viewDidLoad事件中,增加一个图片及定时器并启动,这里的pic请在头文件中定义。

-(void)viewDidLoad{
 [super viewDidLoad];
 self.pic = [UIImage imageNamed:@"snow.png"];//初始化图片
 //启动定时器,实现飘雪效果
 [NSTimer scheduledTimerWithTimeInterval:(0.2) target:self selector:@selector(ontime) userInfo:nil repeats:YES];
}

然后再实现定时器定时调用的ontime方法:
-(void)ontime{
 UIImageView *view = [[UIImageView alloc] initWithImage:pic];//声明一个UIImageView对象,用来添加图片
 view.alpha = 0.5;//设置该view的alpha为0.5,半透明的
 int x = round(random()20);//随机得到该图片的x坐标
 int y = round(random()20);//这个是该图片移动的最后坐标x轴的
 int s = round(random())+10;//这个是定义雪花图片的大小
 int sp = 1/round(random()0)+1;//这个是速度
 view.frame = CGRectMake(x, -50, s, s);//雪花开始的大小和位置
 [self.view addSubview:view];//添加该view
 [UIView beginAnimations:nil context:view];//开始动画
 [UIView setAnimationDuration:10*sp];//设定速度
 view.frame = CGRectMake(y, 500, s, s);//设定该雪
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,