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转化成类
plistArray = [NSObject arrayFromJSON:plistArray ofObjects:@"StartImage"];
5、通过GET请求获取数据:
- (void)refreshImagesPlist{
NSString *aPath = @"api/wallpaper/wallpapers";
NSDictionary *params = @{@"type" : @"3"};
[[CodingNetAPIClient sharedJsonClient] GET:aPath parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) {
DebugLog(@"\n===========response===========\n%@:\n%@", aPath, responseObject);
id error = [self handleResponse:responseObject];
if (!error) {
NSArray *resultA = [responseObject valueForKey:@"data"];
if ([self createFolder:[self downloadPath]]) {
if ([resultA writeToFile:[self pathOfSTPlist] atomically:YES]) {
[[StartImagesManager shareManager] startDownloadImages];
}
}
}
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
DebugLog(@"\n===========response===========\n%@:\n%@", aPath, error);
}];
}
这里的GET方法,其实是调用AFN里面的方法,这里说明一点,就是parameters 参数的传入方式和意义, 传入方式参考上面就可以,意义:
/test/demo_form.asp?name1=value1&name2=value2
- (AFHTTPRequestOperation *)GET:(NSString *)URLString
parameters:(id)parameters
success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success
failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure;
6、下载图片 用的是AFN网络库提供的方法。
- (void)startDownloadImage{
NSURLSessionConfiguration *configuration = [NSURLSessionConfiguration defaultSessionConfiguration];
AFURLSessionManager *manager = [[AFURLSessionManager alloc] initWithSessionConfiguration:configuration];
NSURL *URL = [NSURL URLWithString:self.url];
NSURLRequest *request = [NSURLRequest requestWithURL:URL];
NSURLSessionDownloadTask *downloadTask = [manager downloadTaskWithRequest:request progress:nil destination:^NSURL *(NSURL *targetPath, NSURLResponse *response) {
NSString *documentPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
NSString *pathDisk = [[documentPath stringByAppendingPathComponent:@"Coding_StartImages"] stringByAppendingPathComponent:[response suggestedFilename]];
return [NSURL fileURLWithPath:pathDisk];
} completionHandler:^(NSURLResponse *response, NSURL *filePath, NSError *error) {
DebugLog(@"downloaded file_path is to: %@", filePath);
}];
[downloadTask resume];
}
7、初步了解动画
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion NS_AVAILABLE_IOS(4_0); // delay = 0.0, options = 0
_manage