启用分页和缩放的 UIScrollView 图像/照片查看器

UIScrollView image/photo viewer with paging enabled and zooming(启用分页和缩放的 UIScrollView 图像/照片查看器)

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

问题描述

好的,我认为是时候在互联网上为这个问题建立一个官方位置了:How to make a UIScrollView photoviewer with paging and zooming.欢迎我的 UIScrollView 黑客伙伴.

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

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

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

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

所以想法是在开始缩放时删除所有其他视图,并将当前视图移动到 scrollview 中的 (0, 0),更新 contentsize 等等.然后当您放大到 1.0f 时,它会重新添加其他视图并将所有内容恢复原状.

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

我在 3.0 SDK 发行说明:

<块引用>UIScrollView:缩放后,内容插入被忽略,内容留在错误的位置.

这听起来像是这里正在发生的事情.放大后,由于您更改了偏移等,视图将移出屏幕.

我已经在这方面花费了几个小时,但我正在慢慢意识到这根本行不通.

Three20 的照片查看器是不可能的:它太重了,而且有太多不必要的 UI 和其他行为.

内置的照片应用似乎有一些魔力.如果您放大图像并平移到远边缘,则当前照片会独立于旁边的照片移动,这不是您在使用标准 UIScrollView 尝试时所得到的.

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

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

解决方案

更新

因为下面的消息,我删除了之前的回答……

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

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

检查这个

还有,这里是 iTunes WWDC 页面的链接:

检查一下

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.

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

I found the following project on github:

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

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.

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.

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.

I found one interesting note in the "Known Issues" of the 3.0 SDK release notes:

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's photo viewer is out of the question: it's too heavy weight and there is too much unnecessary UI and other behaviour.

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.

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

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

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

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.

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

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

Check This

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

本文标题为:启用分页和缩放的 UIScrollView 图像/照片查看器

基础教程推荐