线程异步加载图片

线程异步加载图片

-(void)loadImageRes

{

    WaitingView* waittingView = [WaitingView waittingView];

    //异步加载数据

    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);

dispatch_async(queue, ^{

        

        dispatch_async(dispatch_get_main_queue(), ^{

            waittingView.center = CGPointMake(320/2, 460/2 + 50);

            [self.window addSubview:waittingView];

            [waittingView startActivityWithText:@"正在拷贝图片!请不要退出。"]; //\n 请耐心等待,不要退出。

            

            

           });

        for (int i = 1; i < 13; i++)

        {

            if (![MHFile isDirectoryExistAtPath:[NSString stringWithFormat:@"%@%d",[MHFile getCacheFilePath:IMAGE_DIR],i]])

            {

                [[NSFileManager defaultManager] createDirectoryAtPath:[NSString stringWithFormat:@"%@%d",[MHFile getCacheFilePath:IMAGE_DIR],i] withIntermediateDirectories:YES attributes:nil error:nil];

                

                ZipArchive* zipFile = [[ZipArchive alloc] init];

                [zipFile UnzipOpenFile:[MHFile getResourcesFile:[NSString stringWithFormat:@"figure%d.zip",i]] ];

                [zipFile UnzipFileTo:[NSString stringWithFormat:@"%@/Library/Caches/%@", NSHomeDirectory(),IMAGE_DIR] overWrite:YES];

                [zipFile UnzipCloseFile];

                [zipFile release];

            }

        }

 

        

dispatch_async(dispatch_get_main_queue(), ^{

            

            [waittingView stopActivity];

            [waittingView removeFromSuperview];

            [self initControllers];

            

            [self initTabBarImages];

            

            [self initTabBarController];

            

            self.window.rootViewController = _mhTabBarController;

            

            if ([[NSUserDefaults standardUserDefaults] boolForKey:IS_SHOW_HELP_VIWE] == NO)

            {

                [[NSUserDefaults standardUserDefaults] setBool:YES forKey:IS_SHOW_HELP_VIWE];

                ShowHelpView* helpView = [[ShowHelpView alloc] initWithFrame:CGRectMake(0, 0, 320, 460+(iPhone5?88:0))];

                helpView.delegate = self;

                [_mhTabBarController.view addSubview:helpView];

                [helpView release];

            }

 });

        

});

 

}

 
posted @ 2012-12-13 09:54  六界剑仙  阅读(159)  评论(0)    收藏  举报