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 中平铺图像而无需手动创建


- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01