Is it possible to tile images in a UIScrollView without having to manually create all the tiles?(是否可以在 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;
}
问候,迪帕
这篇关于是否可以在 UIScrollView 中平铺图像而无需手动创建所有平铺?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:是否可以在 UIScrollView 中平铺图像而无需手动创建


基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01