久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何實現具有 1000 多個子視圖的 UIScrollView?

How to implement UIScrollView with 1000+ subviews?(如何實現具有 1000 多個子視圖的 UIScrollView?)
本文介紹了如何實現具有 1000 多個子視圖的 UIScrollView?的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在努力編寫應用程序的一部分,該應用程序的行為應該類似于原生 iphone 照片應用程序.查看了 Orielly 的 iphone sdk 應用程序開發書,其中提供了實現這種所謂的頁面滑動的示例代碼.那里的代碼首先創建了所有子視圖,然后隱藏/取消隱藏它們.在給定時間,只有 3 個子視圖可見,其余的被隱藏.經過一番努力,我讓它與當時只有大約 15 頁的應用程序一起工作.

I am struggling with writing portion of an app which should behave like the native iphone photo app. Looked at iphone sdk app development book from Orielly which gave an example code for implementing this so-called page-flicking. The code there first created all subviews and then hide/unhide them. At a given time only 3 subviews are visible rest are hidden. After much effort I got it working with app which at that time had only around 15 pages.

當我添加 300 頁時,很明顯這種預先分配這么多子視圖的方法存在性能/內存問題.然后我想可能就我的情況而言,我應該只分配 3 個子視圖,而不是隱藏/取消隱藏它們.可能我應該在運行時刪除/添加子視圖.但是不知道 UIScrollView 是否可以動態更新內容.例如,如 UIScrollView 所理解的,一開始有 3 個幀位于屏幕的不同 x 偏移量(0、320、640).一旦用戶移動到第 3 頁,我如何確保我能夠添加第 4 頁并刪除第 1 頁,但 UIScrollView 不會混淆?

As soon as I added 300 pages, it became clear that there are performance/memory issues with that approach of pre-allocating so many subviews. Then I thought may be for my case I should just allocate 3 subviews and instead of hide/unhide them. May be I should just remove/add subviews at runtime. But can't figure out whether UIScrollView can dynamically update contents. For example, at the start there are 3 frames at different x-offsets ( 0, 320, 640 ) from the screen as understood by UIScrollView. Once user moves to 3rd page how do I make sure I am able to add 4th page and remove 1st page and yet UIScrollView doesn't get confused ?

希望有針對此類問題的標準解決方案...有人可以指導嗎?

Hoping there is a standard solution to this kind of problem...can someone guide ?

推薦答案

UIScrollView 只是 UIView 的一個子類,因此可以在運行時添加和刪除子視圖.假設您有固定寬度的照片(320 像素)并且有 300 張,那么您的主視圖將是 300 * 320 像素寬.創建滾動視圖時,將框架初始化為那么寬.

UIScrollView is just a subclass of UIView so it's possible to add and remove subviews at runtime. Assuming you have fixed width photos (320px) and there are 300 of them, then your main view would be 300 * 320 pixels wide. When creating the scroll view, initialize the frame to be that wide.

因此,滾動視圖的框架將具有 (0, 0) 到 (96000, 480) 的尺寸.每當您添加子視圖時,您都必須更改它的框架,使其適合其父視圖中的正確位置.

So the scroll view's frame would have the dimensions (0, 0) to (96000, 480). Whenever you are adding a subview, you will have to change it's frame so it fits in the correct position in its parent view.

假設我們將第四張照片添加到滾動視圖中.它的幀將從 (960, 480) 到 (1280, 480).如果您可以以某種方式將索引與每張圖片相關聯,那么這很容易計算.然后用它來計算索引從0開始的圖片幀:

So let's say, we are adding the 4th photo to the scroll view. It's frame would be from (960, 480) to (1280, 480). That is easily to calculate, if you can somehow associate an index with each picture. Then use this to calculate the picture's frame where indexes start at 0:

Top-Left -- (320 * (index - 1), 0)

Bottom-Right -- (320 * index, 480)

刪除第一張圖片/子視圖應該很容易.保留當前屏幕上的 3 個子視圖的數組.每當你在屏幕上添加一個新的子視圖時,也要將它添加到這個數組的末尾,然后從屏幕上刪除這個數組中的第一個子視圖.

Removing the first picture/subview should be easy. Keep an array of the 3 subviews currently on-screen. Whenever you are adding a new subview to the screen, also add it to the end of this array, and then remove the first subview in this array from the screen too.

這篇關于如何實現具有 1000 多個子視圖的 UIScrollView?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

get index or tag value from imageview tap gesture(從 imageview 點擊手勢獲取索引或標簽值)
UIScrollView not scrolling regardless of large contentSize(無論內容大小如何,UIScrollView 都不會滾動)
Clean autorotation transitions in a paging UIScrollView(清除分頁 UIScrollView 中的自動旋轉轉換)
How to create an image from a UIView / UIScrollView(如何從 UIView/UIScrollView 創建圖像)
How to auto scroll UIScrollView using timer?(如何使用計時器自動滾動 UIScrollView?)
Programmatically force a UIScrollView to stop scrolling, for sharing a table view with multiple data sources(以編程方式強制 UIScrollView 停止滾動,以便與多個數據源共享表格視圖) - IT屋-程序員軟件開發技術分享
主站蜘蛛池模板: 99精品视频免费观看 | 国产视频h | 亚洲+变态+欧美+另类+精品 | 国产精品高潮呻吟久久 | 亚洲一区二区精品视频在线观看 | 成人自拍视频网站 | 国产一区二区三区高清 | 伊人久操 | 日韩中文字幕在线 | 欧美综合一区二区 | 免费三级网 | 国产欧美一区二区三区免费 | 国产清纯白嫩初高生视频在线观看 | 欧美特级黄色 | 日本一区二区三区在线观看 | 亚洲精品v| 久久精品国产亚洲一区二区 | 久久国产传媒 | 日韩久久久久 | 99热视| 99爱视频 | 高清av一区| 国产欧美精品一区二区三区 | 日韩视频专区 | 男人天堂久久久 | 毛片免费在线 | 日韩欧美国产综合 | 成年人免费在线视频 | 狠狠干2020| 亚洲精品乱码久久久久久按摩观 | 成人在线视频免费看 | 国产91久久精品一区二区 | 日韩性在线 | 久久久久久久久久久久亚洲 | 精品久久久久久久久久久久久久 | 日本精品一区二区三区在线观看视频 | 黄色小视频大全 | 麻豆av网站 | 日韩在线国产 | 免费一区 | 国产小视频在线 |