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

刷新/重新加載 UIScrollView 的最佳方法

Best way to refresh/reload UIScrollView(刷新/重新加載 UIScrollView 的最佳方法)
本文介紹了刷新/重新加載 UIScrollView 的最佳方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一種方法可以將一些子視圖(圖像/按鈕)添加到我的 ScrollView.

I have a method that adds some subviews (images/buttons) to my ScrollView.

問題是,用戶可以從 ScrollView 外部點擊一個按鈕,該按鈕將更改 ScrollView 的內容.

The thing is that from outside of the ScrollView the user can tap a button that will change the content of the ScrollView.

有沒有比重置"ScrollView更好的方法:

Is there any decent way to "reset" the ScrollView better than:

for (UIView * view in myScrollView.subViews) {
    [view removeFromSuperview];
}

請注意,此解決方案移除了指示 ScrollView 上位置的欄

Note that this solution removes the bar to indicate the position on the ScrollView

推薦答案

調用 setNeedsDisplay 只是重新繪制滾動視圖,而不是實際刪除其中的內容.

Calling setNeedsDisplay is just going to redraw your scroll view, not actually remove the content inside of it.

正如您所發現的,在所有滾動視圖子視圖上調用 removeFromSuperview 有時也會導致滾動條也被刪除(不是很好).

As you've discovered, calling removeFromSuperview on all scroll view subviews will result in your scroll bars sometimes being removed as well (not great).

有幾種方法可以解決這個問題:第一種是維護一個不同的數組,其中包含您自己添加到滾動視圖中的所有視圖.然后,您可以只迭代這個數組.在我看來,這可能是最好的方法.

There are a couple of approaches around this: the first is to maintain a distinct array containing all the views you yourself have added to the scroll view. You can then just iterate through this array instead. In my view this is probably the best approach.

另一種略顯老套的方法是在遍歷視圖時對其進行測試:

The other, slightly hacky, way is to test the views as you iterate through them:

for (UIView *view in self.contentView.subviews)
{
    if (![view isKindOfClass:[UIImageView class]])
        [view removeFromSuperview];
}

因為滾動條本身是 UIImageView 子類,所以不會刪除它們.但是話又說回來,如果您自己使用圖像視圖,它們也不會被刪除,并且不能保證在未來的 iOS 版本中它們將保持圖像視圖.

Because the scroll bars are themselves a UIImageView subclass this will not remove them. But then again, if you're using image views yourself they won't get removed either, and there's no guarantee in future iOS versions they will remain image views.

使用我的第一種方法要好得多,只需保留一個包含您添加的所有視圖的數組.

So much better to go with my first approach and just keep an array around with all the views you've added.

這篇關于刷新/重新加載 UIScrollView 的最佳方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

how to set scrollview content size in swift 3.0(如何在 swift 3.0 中設置滾動視圖內容大小)
Stop a UITableView from automatically scrolling(阻止 UITableView 自動滾動)
iOS UIScrollView Lazy Loading(iOS UIScrollView 延遲加載)
using iOS 6.0 SDK and building for iOS 5 Target causes UIScrollView setMinimumZoomScale to fail when running on iOS 5 simulator(在 iOS 5 模擬器上運行時,使用 iOS 6.0 SDK 并為 iOS 5 Target 構建會導致 UIScrollView setMinimumZ
Create partial-screen UIPageViewController programmatically(以編程方式創建部分屏幕 UIPageViewController)
how to make an ImageView zoomable with or without ScrollView.?(如何使用或不使用 ScrollView 使 ImageView 可縮放?)
主站蜘蛛池模板: 国产一级在线观看 | 黄色免费在线观看网址 | 国产激情免费视频 | 国产欧美精品一区二区三区 | 亚洲成人av在线 | 中文字幕日韩欧美 | www国产成人免费观看视频 | 91国在线视频| 亚洲日韩中文字幕一区 | 欧美一二三四成人免费视频 | 亚洲精品视频在线观看免费 | 超碰在线播 | 99在线观看视频 | 91麻豆精品国产91久久久更新资源速度超快 | 国产.com | 日韩中文字幕2019 | 每日在线更新av | 久久精品99久久 | 国产专区视频 | 成人av电影天堂 | 在线免费观看亚洲 | 91久久精品国产 | 一区二区三区视频在线免费观看 | 午夜激情视频在线 | 国产精品久久久久久久久久 | 蜜桃在线播放 | www亚洲一区 | 国产一区二区在线免费观看 | 欧美午夜精品久久久久久浪潮 | 色av一区 | 亚洲aⅴ一区二区 | 丁香久久 | 国产精品久久久久久久久久久久久 | 99re国产视频 | 凹凸日日摸日日碰夜夜 | 欧美精选一区二区 | 中文字幕精品一区二区三区在线 | 国产精品中文字幕一区二区三区 | 午夜久久久久久久久久一区二区 | 国产一区二区在线播放视频 | 亚洲福利一区 |