如何创建 iPad 文档预览界面,如 iWorks for iPad 中的界面

发布于 2024-10-09 12:12:49 字数 657 浏览 1 评论 0原文

愿意为工作示例授予+500 赏金。

据我所知,在 iPad 上实现文档预览界面的源代码示例只有 2 个,例如 Number、Pages 等中的源代码示例。

infoNgenOmniGroup 框架

还有其他示例吗? infoNgen 是一个很好的简单示例,但是,代码非常草率,而且写得很糟糕,非常无组织。

OmniGroup 是一个很棒的库,但对于简单的项目来说太复杂了。

alt text

更新

我能够分解 infoNgen 的项目并制作一个带有 HTML 预览的准系统文档查看器,这似乎可以工作可以很好地更新文档中的信息并使其与预览保持同步。现在要解决的唯一问题是在应用程序退出并重新启动时保存文档。 +500 赏金仍然可用于工作示例,但是,除非发布了工作示例,否则我不会打开赏金。

Willing to award a +500 bounty for a working example.

There are only 2 source code examples that I know of to accomplish the Document Preview interface on the iPad, like those found in Number, Pages, etc.

infoNgen and OmniGroup Framework

Are there any other example? infoNgen is a good simple example, however, the code is extremely sloppy, and horribly written, very unorganized.

OmniGroup is an awesome library, but way too complicated for simple projects.

alt text

Update

I was able to break down infoNgen's project and make a barebones document viewer with an HTML preview, which seems to work fairly well with updating info in the document and keeping it sync'd with the preview. Only issue now to tackle is making the documents save for when the app exits and relaunches. The +500 bounty is still available to a working example, however, i am not going to open the bounty unless there are working examples posted.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你又不是我 2024-10-16 12:12:49

“包装视图”是主视图控制器,它将显示整个预览轮播。

“轮播”本身是一个 UIScrollView。只需创建滚动视图并将 pagingEnabled 属性设置为 YES 即可。通过设置框架将其布局到适当的尺寸,然后将其添加到包装视图控制器中。您还需要将轮播视图的 contentSize 属性设置为足够大。通过将文档数量加上另外两个文档的宽度乘以轮播的宽度来计算此值。 如果您希望两侧的文档显示一点,则将文档数量乘以滚动视图的宽度减去几个像素。

编辑

实际上,谷歌搜索一下这个有点问题让我看到这篇文章,它描述了实现此目的的另一种方法。本质上,您将滚动视图包装在自定义 UIView 子类中,该子类将触摸转发到 UIScrollView。这是必要的,因为 UIScrollView 只能“翻页”与它一样宽的页面。使用我的“将侧视图调整几个像素”方法,您最终会得到一个不错的预览,但偏移会导致滚动时预览跳跃。 (我在拼凑示例代码时尝试了我的方法。正如我刚才所解释的,它不起作用。)在使用自定义包装器之前,我将尝试另一种方法。 (我想知道内容插入是否有效。)

结束编辑

请注意,正如 Matthew 在评论中正确指出的那样,您实际上只创建了所需的 3 个视图,如稍后所述。

您的文档预览可以是您喜欢的任何对象,正如您提到的,UIWebView 可用于呈现 HTML。无论您想使用什么来表示缩略图,技巧都是将它们布置出来。

我假设您有一个对象数组,尽管您可能使用核心数据来存储您的信息。要显示文档预览,请将它们添加到滚动视图,但位于沿“X”坐标的正确位置。要计算该值,请将当前文档的索引乘以滚动视图的宽度。使用文档预览的 setFrame 方法应用此值。您还需要渲染当前预览之前和之后的预览,以便获得流畅的动画。

为了处理渲染和滚动,您需要将包装器制作为 UIScrollViewDelegate。每次滚动动画完成时,委托应该告诉 UIScrollView 删除并重新渲染滚动视图。

为了处理“轮播效果”(第一个和最后一个文档之间发生的循环),您的 UIScrollViewDelegate 应检查 contentOffset 属性并确定我们是否位于最后一个对象。如果显示最后一个对象,请将第一个对象渲染到右侧,就像处理其他对象一样。如果随后滚动到正确的对象,则使用 [scrollViewscrollToRect: CGRectMake(0,0,scrollView.rect.size.width,scrollView.rect.sizeheight)animated:NO]; 代码无缝跳转到开头。 (对第一个预览执行相同的操作。渲染左侧的第一个和最后一个预览,如有必要,以相同的方式处理)。

我希望这个答案有所帮助。我会尽可能发布代码。

祝你好运!

编辑2:

现在我想了一下,这整个分页控件可以打包到UIScrollView子类或类别中。我将尝试做这件事。

The "wrapper view" is the main view controller that will be showing your whole preview carousel.

The "carousel" itself is a UIScrollView. Simply create the scroll view and set the pagingEnabled property to YES. Lay it out to the appropriate dimensions by settings the frame and then add it to your wrapper view controller. You will also want to set the contentSize property of the carousel view to be large enough. Calculate this by multiplying the number of documents, plus the width of two more documents, by the width of the carousel. If you want the documents on either side to show a little, then multiply the number of documents by the width of the scroll view minus a few pixels.

EDIT

Actually, googling this problem a bit led me to this post which describes an alternate method of implementing this. Essentially, you wrap the scroll view inside of a custom UIView subclass, which forwards touches to the UIScrollView. This is necessary, because a UIScrollView can only "page" for pages that are as wide as it. Using my "adjust the side views by a few pixels" method, you end up with a nice preview, but the offsets will cause the previews to jump when scrolling. (I tried my method while throwing together sample code. As I just explained, it didn't work.) I'm going to try one more method before using the custom wrapper. (I wonder if content insets would work.)

End Edit

Note that, as Matthew correctly pointed out in the comments, you only actually create the 3 views that you need, as described later on.

Your document previews can be whatever object you like, as you mentioned, a UIWebView can be used to render HTML. Regardless of what you want to use to represent your thumbnails, the trick is going to be laying them out.

I am assuming that you have an array of objects, although you may be using Core Data to store your information. To show your document previews, add them to the scroll view, but at the proper location along the "X" coordinate. To calculate that value, multiply the index of the current document by the width of the scroll view. Apply this value using the setFrame method of the document preview. You will also want to render the preview before the current one and the one after, so you have smooth animation.

To handle rendering and scrolling, you will want to make your wrapper into a UIScrollViewDelegate. The delegate should tell the UIScrollView to remove and re-render the scrollviews each time the scrolling animation finishes.

To handle the "carousel effect" (the loop that occurs between the first and last documents), your UIScrollViewDelegate should check the contentOffset property and determine if we are at the last object. If the last object is being shown, render the the first object to the right, like you would any other. If the right object is then scrolled to, you use the [scrollView scrollToRect: CGRectMake(0,0,scrollView.rect.size.width,scrollView.rect.sizeheight) animated:NO]; code to seamlessly jump to the beginning. (Do the same for the first preview. Render the first and the last one on the left, handling it the same way if necessary).

I hope this answer helps somewhat. I will post code when I can.

Good luck!

Edit 2:

Now that I think about it, this whole paging control can be packaged into a UIScrollView subclass or category. I'm going to try to work on this one.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文