开源项目Coding学习笔记(1):EaseStartView --- 第一个界面

EaseStartView *startView = [EaseStartView startView];    @weakify(self);    [startView startAnimationWithCompletionBlock:^(EaseStartView *easeStartView) {        @strongify(self);        [self completionStartAnimationWithOptions:launchOptions];    }];


这个效果主要是刚进入应用时有一张图片加上logo,从无到有,然后向左移除界面的效果。

通过EaseStartView类来实现,而且可以通过网络下载不同的图片,截图如下:



技术点:

1、单例的创建:

@implementation StartImagesManager+ (instancetype)shareManager{    static StartImagesManager *shared_manager = nil;    static dispatch_once_t pred; //这里暂时还不明白,以后研究下    dispatch_once(&pred, ^{        shared_manager = [[self alloc] init];    });    return shared_manager;}

2、ios路径,文件操作相关的东西

可以参考下面的博客:

http://blog.csdn.net/totogo2010/article/details/7671144

http://blog.csdn.net/xyz_lmn/article/details/8968213

- (NSString *)downloadPath{    NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];    NSString *downloadPath = [documentPath stringByAppendingPathComponent:@"Coding_StartImages"];    return downloadPath;}
- (BOOL)fileExistsAtPath:(NSString *)path isDirectory:(BOOL *)isDirectory;

这个方法我开始理解错误了,我开始理解为isDirectory这个变量用来说明我们传入的是目录还是文件,其实这个是一个返回值。这个方法用来返回文件是否存在,(BOOL *)isDirectory这个值表明我们传入的文件路径是否是目录,这个也是一个返回值。

  BOOL isDir = NO;    NSFileManager *fileManager = [NSFileManager defaultManager];    BOOL existed = [fileManager fileExistsAtPath:path isDirectory:&isDir];    BOOL isCreated = NO;    if (!(isDir == YES && existed == YES)){        isCreated = [fileManager createDirectoryAtPath:path withIntermediateDirectories:YES attributes:nil error:nil];    }else{        isCreated = YES;    }

3、How do I prevent files from being backed up to iCloud and iTunes?(摘自网络) 阻止文件被iCloud和iTunes备份。

  +(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

参考网址:

https://developer.apple.com/library/ios/qa/qa1719/_index.html

https://gist.github.com/weekwood/4527957

4、把json转化成类

 
 
  1. plistArray = [NSObject arrayFromJSON:plistArray ofObjects:@"StartImage"];

5、通过GET请求获取数据:

 
 
  1. - (void)refreshImagesPlist{

  2.    NSString *aPath = @"api/wallpaper/wallpapers";
  3.    NSDictionary *params = @{@"type" : @"3"};
  4.    [[CodingNetAPIClient sharedJsonClient] GET:aPath parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
  5.        DebugLog(@"\n===========response===========\n%@:\n%@", aPath, responseObject);
  6.        id error = [self handleResponse:responseObject];
  7.        if (!error) {
  8.            NSArray *resultA = [responseObject valueForKey:@"data"];
  9.            if ([self createFolder:[self downloadPath]]) {
  10.                if ([resultA writeToFile:[self pathOfSTPlist] atomically:YES]) {
  11.                    [[StartImagesManager shareManager] startDownloadImages];
  12.                }
  13.            }
  14.        }
  15.    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
  16.        DebugLog(@"\n===========response===========\n%@:\n%@", aPath, error);
  17.    }];
  18. }

这里的GET方法,其实是调用AFN里面的方法,这里说明一点,就是parameters 参数的传入方式和意义, 传入方式参考上面就可以,意义:

/test/demo_form.asp?name1=value1&name2=value2

 
 
  1. - (AFHTTPRequestOperation *)GET:(NSString *)URLString
  2.                     parameters:(id)parameters
  3.                        success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
  4.                        failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;

6、下载图片 用的是AFN网络库提供的方法。

 
 
  1. - (void)startDownloadImage{
  2.    NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
  3.    AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
  4.    NSURL *URL = [NSURL URLWithString:self.url];
  5.    NSURLRequest *request = [NSURLRequest requestWithURL:URL];
  6.    NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
  7.        NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
  8.        NSString *pathDisk = [[documentPath stringByAppendingPathComponent:@"Coding_StartImages"] stringByAppendingPathComponent:[response suggestedFilename]];
  9.        return [NSURL fileURLWithPath:pathDisk];
  10.    } completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
  11.        DebugLog(@"downloaded file_path is to: %@", filePath);
  12.    }];
  13.    [downloadTask resume];
  14. }

7、初步了解动画

  
  
  1. + (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0

_manage

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值