UIScrollView图像/照片查看器,启用了分页和缩放功能 [英] UIScrollView image/photo viewer with paging enabled and zooming

查看:136
本文介绍了UIScrollView图像/照片查看器,启用了分页和缩放功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,我认为现在是时候在互联网上找到这个问题的正式位置:如何使用分页和缩放制作 UIScrollView photoviewer。欢迎我的同事 UIScrollView 黑客。

OK, I think it's time to make an official place on the internet for this problem: How to make a UIScrollView photoviewer with paging and zooming. Welcome my fellow UIScrollView hackers.

我有一个 UIScrollView 启用分页,我正在显示 UIImageViews ,就像内置的照片应用程序一样。 (这听起来很熟悉吗?)

I have a UIScrollView with paging enabled, and I'm displaying UIImageViews like the built-in photos app. (Does this sound familiar yet?)

我在github上找到了以下项目:

I found the following project on github:

http://wiki.github.com/andreyvit/ScrollingMadness

其中显示了启用分页时如何在滚动视图中实现缩放。如果其他人尝试这一点,我实际上必须删除 UIScrollView 子类并使用本机类,否则它不起作用。我认为这是因为3.0 SDK中的更改与滚动视图拦截触摸事件的方式有关。

Which shows how to implement zooming in a scroll view while paging is enabled. If anyone else tries this out, I actually had to remove the UIScrollView subclass and use the native class otherwise it doesn't work. I think it's because of changes in the 3.0 SDK relating to how the scroll view intercepts touch events.

所以想法是在开始缩放时删除所有其他视图,并将当前视图移动到 scrollview 中的(0,0),更新 contentsize 等。然后当你缩回到1.0f它会添加其他视图并将所有视图重新排列。

So the the idea is to remove all the other views when you start zooming, and move the current view to (0, 0) in the scrollview, updating the contentsize etc. Then when you zoom back to 1.0f it adds the other views back and puts things all back in order.

无论如何,该项目在模拟器中完美运行,但在设备上有您正在调整视图的一些令人讨厌的移动,这看起来像是因为我们正在更改 contentsize / offset 等等,用于调整视图大小。您必须执行此视图移动,否则您可以向左平移其他视图留下的空白。

Anyway, that project works perfectly in the simulator, but on the device there is some nasty movement of the view you are resizing, which looks like it's caused by the fact we are changing the contentsize/offset etc. for the view being resized. You have to do this view moving otherwise you can pan left through the whitespace left by the other views.

我在<已知问题中找到了一个有趣的注释< a href =http://developer.apple.com/iphone/prerelease/library/releasenotes/General/RN-iPhoneSDK-3/index.html\"rel =noreferrer> 3.0 SDK发行说明:


UIScrollView:缩放后,内容插入将被忽略,内容将保留在错误的位置。
UIScrollView: After zooming, content inset is ignored and content is left in the wrong position.

这听起来就像这里发生的事情。放大后,视图将在屏幕外移动,因为您已经更改了偏移量等。

This kind of sounds like what is happening here. After zooming in, the view will shift offscreen because you have changed the offset etc.

我已经花了好几个小时就已经开始了,我正在放慢心情去实现这只是不起作用。

I've spent hours on this already and I'm slowing coming to the sad realization that this just isn't going to work.

Three20的照片浏览器是不可能的:它太重了,并且有太多不必要的UI和其他行为。

Three20's photo viewer is out of the question: it's too heavy weight and there is too much unnecessary UI and other behaviour.

内置的Photo应用程序似乎有些神奇。如果你放大一个图像并平移到远边,当前的照片会独立于它旁边的照片移动,这不是你用标准的 UIScrollView

The built in Photo app seems to do some magic. If you zoom in on an image and pan to the far edges, the current photo moves independently of the photo next to it which isn't what you get when trying this with a standard UIScrollView.

我见过关于嵌套 UIScrollView 的讨论,但我真的不想去那里。

I've seen discussion about nesting the UIScrollView's but I really don't want to go there.

有没有人使用标准 UIScrollView 进行管理(并且在2.2和3.0 SDK中工作)?我不喜欢滚动我自己的缩放+反弹+平移+分页代码。

Has anybody managed this with the standard UIScrollView (and works in the 2.2 and 3.0 SDK)? I don't fancy rolling my own zoom + bounce + pan + paging code.

推荐答案

UPDATE

UPDATE

由于以下新闻,我删除了之前的答案...

I deleted my previous answer because of the news below...

那些没有听过的人的重大新闻。 Apple已向iphone开发者计划的所有成员发布了2010年WWDC会议视频。讨论的主题之一是他们如何创建照片应用!他们逐步构建了一个非常相似的应用程序,并使所有代码都免费提供。

Big news for those who haven't heard. Apple has released the 2010 WWDC session videos to all members of the iphone developer program. One of the topics discussed is how they created the photos app!!! They build a very similar app step by step and have made all the code available for free.

它也不使用私有api。这是示例代码下载的链接。您可能需要登录才能获得访问权限。

It does not use private api either. Here is a link to the sample code download. You will probably need to login to gain access.

Check This

这里是一个链接iTunes WWDC页面:

And, here is a link to the iTunes WWDC page:

选中此项

这篇关于UIScrollView图像/照片查看器,启用了分页和缩放功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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