問題描述
好的,我認(rèn)為是時候在互聯(lián)網(wǎng)上為這個問題建立一個官方位置了:How to make a UIScrollView
photoviewer with paging and zooming.歡迎我的 UIScrollView
黑客伙伴.
我有一個啟用分頁的 UIScrollView
,并且我正在顯示 UIImageViews
,就像內(nèi)置的照片應(yīng)用程序一樣.(這聽起來是不是很熟悉?)
我在github上找到了以下項目:
https://github.com/andreyvit/ScrollingMadness/wiki
這顯示了如何在啟用分頁時在滾動視圖中實現(xiàn)縮放.如果其他人嘗試這樣做,我實際上必須刪除 UIScrollView
子類并使用本機(jī)類,否則它不起作用.我認(rèn)為這是因為 3.0 SDK 中有關(guān)滾動視圖如何攔截觸摸事件的更改.
所以想法是在開始縮放時刪除所有其他視圖,并將當(dāng)前視圖移動到 scrollview
中的 (0, 0),更新 contentsize
等等.然后當(dāng)您放大到 1.0f 時,它會重新添加其他視圖并將所有內(nèi)容恢復(fù)原狀.
無論如何,該項目在模擬器中運行良好,但在設(shè)備上,您正在調(diào)整大小的視圖有一些令人討厭的移動,這看起來是由于我們正在更改 contentsize
/offset
等用于正在調(diào)整大小的視圖.您必須移動此視圖,否則您可以通過其他視圖留下的空白向左平移.
我在 3.0 SDK 發(fā)行說明:
<塊引用>UIScrollView:縮放后,內(nèi)容插入被忽略,內(nèi)容留在錯誤的位置.這聽起來像是這里正在發(fā)生的事情.放大后,由于您更改了偏移等,視圖將移出屏幕.
我已經(jīng)在這方面花費了幾個小時,但我正在慢慢意識到這根本行不通.
Three20 的照片查看器是不可能的:它太重了,而且有太多不必要的 UI 和其他行為.
內(nèi)置的照片應(yīng)用似乎有一些魔力.如果您放大圖像并平移到遠(yuǎn)邊緣,則當(dāng)前照片會獨立于旁邊的照片移動,這不是您在使用標(biāo)準(zhǔn) UIScrollView
嘗試時所得到的.
我看過關(guān)于嵌套 UIScrollView
的討論,但我真的不想去那里.
有沒有人用標(biāo)準(zhǔn)的 UIScrollView
管理過這個(并且在 2.2 和 3.0 SDK 中工作)?我不喜歡滾動自己的縮放 + 彈跳 + 平移 + 分頁代碼.
更新
因為下面的消息,我刪除了之前的回答……
對于那些沒有聽說過的人來說是個大新聞.Apple 已向 iphone 開發(fā)者計劃的所有成員發(fā)布了 2010 年 WWDC 會議視頻.討論的主題之一是他們?nèi)绾蝿?chuàng)建照片應(yīng)用程序!!!他們逐步構(gòu)建了一個非常相似的應(yīng)用程序,并免費提供了所有代碼.
它也不使用私有 api.這是示例代碼下載的鏈接.您可能需要登錄才能獲得訪問權(quán)限.
檢查這個
還有,這里是 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
這篇關(guān)于啟用分頁和縮放的 UIScrollView 圖像/照片查看器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!