如何创建 iPad 文档预览界面,如 iWorks for iPad 中的界面 [英] How to create iPad Document Preview interface like those found in iWorks for iPad

查看:19
本文介绍了如何创建 iPad 文档预览界面,如 iWorks for iPad 中的界面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

愿意为一个工作示例奖励 +500 奖金.

我所知道的在 iPad 上完成文档预览界面的源代码示例只有 2 个,例如在 Number、Pages 等中找到的那些.

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

结束编辑

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

您的文档预览可以是您喜欢的任何对象,正如您提到的,UIWebView 可用于呈现 HTML.不管你想用什么来表示你的缩略图,诀窍就是把它们布置出来.

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

要处理渲染和滚动,您需要将包装器变成 UIScrollViewDelegate.每次滚动动画完成时,委托都应该告诉 UIScrollView 移除并重新渲染滚动视图.

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

我希望这个答案有所帮助.我会尽快发布代码.

祝你好运!

编辑 2:

现在想来,这整个分页控件可以打包成一个UIScrollView子类或者类.我会努力解决这个问题.

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.

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.

解决方案

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.

这篇关于如何创建 iPad 文档预览界面,如 iWorks for iPad 中的界面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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