久久久久久久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 可縮放?)
主站蜘蛛池模板: 91看片在线 | 欧美日韩三级视频 | 免费网站在线 | 久久久久国产一区二区三区 | 亚洲最新在线 | 精品视频一区二区在线观看 | 国产精品永久免费视频 | 亚洲一区久久 | 在线观看国产h | 国产精品mv在线观看 | 亚洲精品一区中文字幕乱码 | 国产精品久久二区 | 午夜av在线 | 精品二 | 欧美一级欧美一级在线播放 | 99久久婷婷国产综合精品电影 | 激情黄色在线观看 | 日日夜夜天天干 | 国产区在线 | 日韩精品久久久久 | 久久极品 | 成人亚洲一区 | 午夜综合| 欧美888| 精品国产色 | 亚洲一区二区三区在线 | 成人欧美日韩一区二区三区 | 免费视频一区二区三区在线观看 | 麻豆国产精品777777在线 | av在线视 | 久在线 | 伊人久操 | 亚洲精品一区久久久久久 | 久久免费观看视频 | 欧美激情精品久久久久久变态 | 国产精品久久网 | 欧美国产视频 | 国产免费av网 | 国产精品毛片一区二区三区 | 夜夜爽99久久国产综合精品女不卡 | av在线播放国产 |