文章標題

dispatch_async(dispatch_get_global_queue(0, 0), ^{
//處理的耗時操作
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@”http://192.168.1.67:8080/img/luckgo_spxq.png“]];
//通知主線程刷新
dispatch_async(dispatch_get_main_queue(), ^{
UIImage *image = [UIImage imageWithData:data];
CGSize size = image.size;
CGFloat width = size.width;
CGFloat height = size.height;
CGFloat scale = height/width;

        CGFloat scaledWidth = SCREEN_WIDTH;
        CGFloat scaledHeight = SCREEN_WIDTH * scale;
        UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 64, scaledWidth, scaledHeight)];
        imageView.image = image;
        [self.view addSubview:imageView];
    });
});
發佈了14 篇原創文章 · 獲贊 2 · 訪問量 4萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章