- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个 140 页的测试 PDF(完整的 Adobe PDF 规范,http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/pdf/pdfs/adobe_supplement_iso32000.pdf)并在 iBooks 中打开它。然后切换到索引(缩略图) View 。如果我滚动到末尾的速度足够快,我可以看到我滚动的速度比 iBooks 呈现页面的速度快,但它在 iPad 2 上很快就 catch 了。我从中学到了两件事:
问题是他们是怎么做到的?我编写了一些代码,将 PDF 的每一页作为图像获取,将其添加到 UIImageView 并将其添加到 ScrollView 。
我使用与 iBooks 相同的技术和布局。它的呈现速度与 iBooks 一样快,但内存消耗非常大,尤其是在滚动应用程序一段时间后完全卡住时。有人能指出我正确的方向吗?我已经删除了用于测试的 PDF 渲染,它非常快,所以我可以将其固定到缩略图生成。
编辑:如果从下面的代码中删除 PDF 生成并返回一个空的 UIImageView
,性能仍然非常差。所以我的假设是 UIImageView 导致了问题。如何在不需要 140 UIImageViews
的情况下将 PDF 缩略图绘制到我的 UIScrollView
上?
对于那些使用 Monotouch 的公司,这是我用来渲染拇指的代码,也许它显示出一个明显的弱点:
/// <summary>
/// Gets the low res page preview of a PDF page. Does a quick image render of the page.
/// </summary>
/// <param name="iPage">the number of the page to render</param>
/// <param name="oTergetRect">the target rect to fit the PDF page into</param>
/// <returns>
/// The low res page image view.
/// </returns>
public static UIImageView GetLowResPagePreview (CGPDFPage oPdfPage, RectangleF oTargetRect)
{
RectangleF oOriginalPdfPageRect = oPdfPage.GetBoxRect (CGPDFBox.Media);
RectangleF oPdfPageRect = PdfViewerHelpers.RotateRectangle( oPdfPage.GetBoxRect (CGPDFBox.Media), oPdfPage.RotationAngle);
// If preview is requested for the PDF index view, render a smaller version.
if (!oTargetRect.IsEmpty)
{
// Resize the PDF page so that it fits the target rectangle.
oPdfPageRect = new RectangleF (new PointF (0, 0), GetFittingBox (oTargetRect.Size, oPdfPageRect.Size));
}
// Create a low res image representation of the PDF page to display before the TiledPDFView
// renders its content.
int iWidth = Convert.ToInt32 ( oPdfPageRect.Size.Width );
int iHeight = Convert.ToInt32 ( oPdfPageRect.Size.Height );
CGColorSpace oColorSpace = CGColorSpace.CreateDeviceRGB();
CGBitmapContext oContext = new CGBitmapContext(null, iWidth, iHeight, 8, iWidth * 4, oColorSpace, CGImageAlphaInfo.PremultipliedLast);
// First fill the background with white.
oContext.SetFillColor (1.0f, 1.0f, 1.0f, 1.0f);
oContext.FillRect (oOriginalPdfPageRect);
// Scale the context so that the PDF page is rendered
// at the correct size for the zoom level.
oContext.ConcatCTM ( oPdfPage.GetDrawingTransform ( CGPDFBox.Media, oPdfPageRect, 0, true ) );
oContext.DrawPDFPage (oPdfPage);
CGImage oImage = oContext.ToImage();
UIImage oBackgroundImage = UIImage.FromImage( oImage );
oContext.Dispose();
oImage.Dispose ();
oColorSpace.Dispose ();
UIImageView oBackgroundImageView = new UIImageView (oBackgroundImage);
oBackgroundImageView.Frame = new RectangleF (new PointF (0, 0), oPdfPageRect.Size);
oBackgroundImageView.ContentMode = UIViewContentMode.ScaleToFill;
oBackgroundImageView.UserInteractionEnabled = false;
oBackgroundImageView.AutoresizingMask = UIViewAutoresizing.None;
return oBackgroundImageView;
}
internal static RectangleF RotateRectangle ( RectangleF oRect, int iRotationAngle )
{
if ( iRotationAngle == 90 || iRotationAngle == 270 )
{
return new RectangleF (oRect.X, oRect.Y, oRect.Height, oRect.Width);
}
return oRect;
}
最佳答案
你不应该使用 140 个 UIImageViews!!!仅使用足以填充该区域的量,然后回收不再显示的那些。
Apple 是如何实现 UITableView 的?你认为他们将所有表格 View 单元格保存在内存中吗??
查看 PhotoScroller 示例代码和相应的 WWDC 2010 视频。我认为它被命名为“Desigining apps with scrollViews”
名称相似的 WWDC 2011 视频延续了相同的 View 重用技巧。
希望这对您有所帮助。
关于objective-c - iBooks 如何在查看 PDF 时如此快速地呈现索引 View ?或者 : how do draw UIImages on UIScrollView directly without UIImageView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8541047/
我正在寻找任何方法来在我为 iBooks 开发的电子书(epub3)中包含带有文本突出显示的音频。 我知道我可以做到这一点,但我找不到任何示例来说明如何在 epub3 中专门为 iBooks 实现此功
我从 Send PDF to iBooks 看到了iBooks打开pdf时如何格式化链接,但如果没有安装iBooks,它会正常打开吗?还是会有什么东西坏了? (我知道,我可以测试一下并找出答案,但也可
Apple 对 ePub 3 脚注的支持详见 Liz Castro . 简而言之,如果脚注链接有 epub:tupe="noteref"格式: 1 脚注文本位于 用 epub:type="footno
我想知道我是否可以开发一个应用程序,从网站下载 epub 格式的书籍,然后通过 iBooks(用于阅读书籍的 iPad 应用程序)访问它来读取该文件。在我看来,问题是应用程序可以访问其自己的沙箱中存在
我的应用程序中有一些 PDF。我想提供一个选项,可以在设备上可能安装的其他第三方电子阅读器应用程序(例如 Stanza 和 iBooks)中打开这些 PDF。 Dropbox 应用程序已成功实现此功能
看着 iBooks 应用程序,我想知道它如何实现文本格式(可能是一个非常简单的 txt 文件),以便它不可滚动,而是分为不同的页面。 我想实现同样的目标,但只能使用可编辑文本。 我需要从哪里开始? U
据我所知,ibooks 格式类似于 epub 格式 http://iphoneincubator.com/blog/apple-events/thoughts-on-ibooks-author ,一堆
是否可以在没有任何 UIDocumentInteractionController 的情况下自动打开我的文档目录中的 .ibooks 文件?也许通过操纵 url 或类似的东西? 我尝试通过共享应用程序
我想通过按钮实现一个特殊的突出显示。我在适用于 iPhone/iPad 的 iBooks 应用程序上找到的一款可以满足我的需求。我认为它非常复杂,因为所有的笔画看起来都不一样。我可以使用一些 CSS-
是否可以在我的应用程序中打开 iBooks 中的文档?我只发现: NSString *stringURL = @"itms-books:"; NSURL *url = [NSURL URLWithSt
我读到 Apple 专有的 .ibooks 格式与 .epub 几乎相似,但我似乎无法在任何地方找到它的文档。是的,我有一个开发者帐户。 我需要比较 ibooks 和 epub 格式以查看差异。 最佳
我正在尝试在 iBooks 中显示一本书的打开动画。任何输入都会有帮助。 最佳答案 我也有同样的要求。我用过this图书馆。根据我的需要做了一些修改。它的工作。尝试一下。 关于iphone - 如何像
当我在 Mac 上使用 iBooks 并用鼠标突出显示某个单词时,会显示英语同义词库: 我希望我的程序能够执行类似的操作 - 在 iBooks 中显示为同义词库。 如何实现它?最简单的想法是识别出某些
我正在开发一个应用程序,它可能具有 ePub/PDF/iBook 形式的潜在配套引用。有一种从您的应用程序中打开 iBooks 的方案,但是是否有一种已知的方法可以打开特定书籍(不是导入书籍,而是在应
任何人都知道 Apple 如何在 iBooks 应用程序中过渡到商店?我知道他们正在使用带有 UIModalTransitionStyleFlipHorizontal 转换样式集的模态视图 Con
我怎样才能列出 iBooks 中的所有图书? 最佳答案 我认为这是不可能的。这是安全问题;我下载了一个应用程序,发现它记录了我买的所有书的所有标题...... 关于ios - 列出存储在 iBooks
我正在尝试使用以下代码通过我的 iPhone 应用程序打开 iBook: - (void)goToiBookStore { NSURL *url = [NSURL URLWithString:
我想创建和应用轮播式 View ,图像在行和列中,其中列数固定,但行数不同。当用户单击图像时,它会打开一个详细 View 。我最初的方法是使用 tableview,将一个单元格作为一行,但这里棘手的部
我正在尝试为 iPad 建立网上商店。现在我想浏览 ibooks 中的产品。我在网上查了一下,但他们都在处理图像、pdf、页面。 这不是我想要的。我想在 xib 文件之间浏览。如果有人对此有任何好的教
iBooks 中的导航栏正是我想要实现的。也就是说,一个透明的顶部栏,左上角有返回按钮,右上角有一些按钮可以调用操作。 但是,我不确定如何实现这种效果。特别是透明度。谁能指出我如何实现这一目标的正确方
我是一名优秀的程序员,十分优秀!