是否可以在UIScrollView中平铺图像而无需手动创建所有图块? [英] Is it possible to tile images in a UIScrollView without having to manually create all the tiles?

查看:112
本文介绍了是否可以在UIScrollView中平铺图像而无需手动创建所有图块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在iPhone示例代码 PhotoScroller 来自WWDC 2010,它们展示了如何通过滚动,缩放和分页图像来完成照片应用程序的相当好的模仿。他们还平铺图像以显示如何显示高分辨率图像并保持良好的性能。

In the iPhone sample code "PhotoScroller" from WWDC 2010, they show how to do a pretty good mimmic of the Photos app with scrolling, zooming, and paging of images. They also tile the images to show how to display high resolution images and maintain good performance.

通过抓取预缩放和剪切图像以实现不同分辨率,在示例代码中实现平铺并将它们放在构成整个图像的网格中。

Tiling is implemented in the sample code by grabbing pre scaled and cut images for different resolutions and placing them in the grid which makes up the entire image.

我的问题是:有没有办法平铺图像而无需手动浏览所有照片并创建砖?照片应用程序如何能够动态显示大图像?

My question is: is there a way to tile images without having to manually go through all your photos and create "tiles"? How is it the Photos app is able to display large images on the fly?

编辑
以下是Deepa的回答代码下面:

Edit Here is the code from Deepa's answer below:

- (UIImage *)tileForScale:(float)scale row:(int)row col:(int)col size:(CGSize)tileSize  image:(UIImage *)inImage
{
CGRect subRect = CGRectMake(col*tileSize.width, row * tileSize.height, tileSize.width, tileSize.height);
CGImageRef tiledImage = CGImageCreateWithImageInRect([inImage CGImage], subRect);
UIImage *tileImage = [UIImage imageWithCGImage:tiledImage]; 
return tileImage;
}


推荐答案

这里是一段代码用于平铺图像生成:

Here goes the piece of code for tiled image generation:

在PhotoScroller源代码中,将tileForScale:row:col:替换为以下内容:

In PhotoScroller source code replace tileForScale: row:col: with the following:

inImage - 要创建图块的图像

inImage - Image that you want to create tiles

- (UIImage *)tileForScale: (float)scale row: (int)row column: (int)col size: (CGSize)tileSize image: (UIImage*)inImage
{
    CGRect subRect = CGRectMake(col*tileSize.width, row * tileSize.height, tileSize.width, tileSize.height);
    CGImageRef tiledImage = CGImageCreateWithImageInRect([inImage CGImage], subRect);
    UIImage *tileImage = [UIImage imageWithCGImage: tiledImage];
    return tileImage;
}

问候,
Deepa

Regards, Deepa

这篇关于是否可以在UIScrollView中平铺图像而无需手动创建所有图块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆