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

UIScrollView 無限滾動(dòng)

UIScrollView Infinite Scrolling(UIScrollView 無限滾動(dòng))
本文介紹了UIScrollView 無限滾動(dòng)的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我正在嘗試設(shè)置一個(gè)無限(水平)滾動(dòng)的滾動(dòng)視圖.

I'm attempting to setup a scrollview with infinite (horizontal) scrolling.

向前滾動(dòng)很容易——我已經(jīng)實(shí)現(xiàn)了 scrollViewDidScroll,當(dāng) contentOffset 接近尾聲時(shí),我將滾動(dòng)視圖的 contentsize 放大并在空間中添加更多數(shù)據(jù)(我將不得不處理稍后會(huì)產(chǎn)生的嚴(yán)重影響!)

Scrolling forward is easy - I have implemented scrollViewDidScroll, and when the contentOffset gets near the end I make the scrollview contentsize bigger and add more data into the space (i'll have to deal with the crippling effect this will have later!)

我的問題是向后滾動(dòng) - 計(jì)劃是看看我何時(shí)接近滾動(dòng)視圖的開頭,然后當(dāng)我確實(shí)使 contentsize 更大時(shí),移動(dòng)現(xiàn)有內(nèi)容,將新數(shù)據(jù)添加到開頭,然后 -重要的是調(diào)整 contentOffset 使視口下的數(shù)據(jù)保持不變.

My problem is scrolling back - the plan is to see when I get near the beginning of the scroll view, then when I do make the contentsize bigger, move the existing content along, add the new data to the beginning and then - importantly adjust the contentOffset so the data under the view port stays the same.

如果我慢慢滾動(dòng)(或啟用分頁),這非常有效,但如果我走得快(甚至不是很快!)它會(huì)發(fā)瘋!代碼如下:

This works perfectly if I scroll slowly (or enable paging) but if I go fast (not even very fast!) it goes mad! Heres the code:

- (void) scrollViewDidScroll:(UIScrollView *)scrollView {

    float pageNumber = scrollView.contentOffset.x / 320;
    float pageCount = scrollView.contentSize.width / 320;

    if (pageNumber > pageCount-4) {
        //Add 10 new pages to end
        mainScrollView.contentSize = CGSizeMake(mainScrollView.contentSize.width + 3200, mainScrollView.contentSize.height);
        //add new data here at (320*pageCount, 0);
    }

    //*** the problem is here - I use updatingScrollingContent to make sure its only called once (for accurate testing!)
    if (pageNumber < 4 && !updatingScrollingContent) {

        updatingScrollingContent = YES;

        mainScrollView.contentSize = CGSizeMake(mainScrollView.contentSize.width + 3200, mainScrollView.contentSize.height);
        mainScrollView.contentOffset = CGPointMake(mainScrollView.contentOffset.x + 3200, 0);
        for (UIView *view in [mainContainerView subviews]) {
            view.frame = CGRectMake(view.frame.origin.x+3200, view.frame.origin.y, view.frame.size.width, view.frame.size.height);
        }
        //add new data here at (0, 0);      
    }

    //** MY CHECK!
    NSLog(@"%f", mainScrollView.contentOffset.x);
}

隨著滾動(dòng)的發(fā)生,日志顯示:1286.5000001285.5000001284.5000001283.5000001282.5000001281.5000001280.500000

As the scrolling happens the log reads: 1286.500000 1285.500000 1284.500000 1283.500000 1282.500000 1281.500000 1280.500000

然后,當(dāng) pageNumber<4 時(shí)(我們即將開始):4479.5000004479.500000

Then, when pageNumber<4 (we're getting near the beginning): 4479.500000 4479.500000

太棒了!- 但數(shù)字應(yīng)該會(huì)在 4,000 秒內(nèi)繼續(xù)下降,但下一個(gè)日志條目顯示:1278.0000001277.0000001276.5000001275.500000等等……

Great! - but the numbers should continue to go down in the 4,000s but the next log entries read: 1278.000000 1277.000000 1276.500000 1275.500000 etc....

從中斷的地方繼續(xù)!

僅作記錄,如果滾動(dòng)緩慢,日志會(huì)顯示:1294.5000001290.0000001284.5000001280.5000004476.0000004476.0000004473.0000004470.0000004467.5000004464.0000004460.5000004457.500000等等……

Just for the record, if scrolled slowly the log reads: 1294.500000 1290.000000 1284.500000 1280.500000 4476.000000 4476.000000 4473.000000 4470.000000 4467.500000 4464.000000 4460.500000 4457.500000 etc....

有什么想法嗎????

謝謝

本.

推薦答案

可能是無論在其中設(shè)置這些數(shù)字,都不會(huì)因?yàn)槟鷮?contentOffset 設(shè)置在其手中而留下深刻印象.所以它只是繼續(xù)設(shè)置它認(rèn)為應(yīng)該是下一個(gè)瞬間的 contentOffset - 而不驗(yàn)證 contentOffset 在此期間是否發(fā)生了變化.

It could be that whatever is setting those numbers in there, is not greatly impressed by you setting the contentOffset under its hands. So it just goes on setting what it thinks should be the contentOffset for the next instant - without verifying if the contentOffset has changed in the meantime.

我會(huì)將 UIScrollView 子類化并將魔法放在 setContentOffset 方法中.根據(jù)我的經(jīng)驗(yàn),所有內(nèi)容偏移更改都通過該方法,即使是內(nèi)部滾動(dòng)引起的內(nèi)容偏移更改.只需在某個(gè)時(shí)候執(zhí)行 [super setContentOffset:..] 即可將消息傳遞給真正的 UIScrollView.

I would subclass UIScrollView and put the magic in the setContentOffset method. In my experience all content-offset changing passes through that method, even the content-offset changing induced by the internal scrolling. Just do [super setContentOffset:..] at some point to pass the message on to the real UIScrollView.

也許如果你把你的換檔動(dòng)作放在那里它會(huì)更好.您至少可以檢測到 contentOffset 的 3000-off 設(shè)置,并在傳遞消息之前對(duì)其進(jìn)行修復(fù).如果您還要覆蓋 contentOffset 方法,您可以嘗試看看是否可以制作一個(gè)虛擬的無限內(nèi)容大小,然后在后臺(tái)"將其縮小到真實(shí)比例.

Maybe if you put your shifting action in there it will work better. You could at least detect the 3000-off setting of contentOffset, and fix it before passing the message on. If you would also override the contentOffset method, you could try and see if you can make a virtual infinite content size, and reduce that to real proportions "under the hood".

這篇關(guān)于UIScrollView 無限滾動(dòng)的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

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

相關(guān)文檔推薦

How to subclass UIScrollView and make the delegate property private(如何繼承 UIScrollView 并使委托屬性私有)
Swift - how to get last taken 3 photos from photo library?(Swift - 如何從照片庫中獲取最后拍攝的 3 張照片?)
Setting contentOffset programmatically triggers scrollViewDidScroll(以編程方式設(shè)置 contentOffset 觸發(fā) scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應(yīng)用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動(dòng)時(shí)暫停 NSTimer)
主站蜘蛛池模板: 欧美片网站免费 | 波多野结衣中文视频 | 欧美精品综合在线 | a黄在线观看 | 夜夜精品浪潮av一区二区三区 | 成人午夜av | 国产91精品久久久久久久网曝门 | 又爽又黄axxx片免费观看 | 一区二区三区欧美在线观看 | 欧美成人第一页 | 国产精品夜夜春夜夜爽久久电影 | 视频在线一区二区 | 81精品国产乱码久久久久久 | 欧美精品一区二区三区蜜桃视频 | 老外几下就让我高潮了 | 亚洲一区精品在线 | 国产精品久久九九 | 91综合网 | 国产激情网站 | 久在线 | 日韩视频在线一区二区 | 国产精品毛片无码 | 午夜爽爽爽男女免费观看 | 精品一区二区三区四区视频 | 超碰综合 | 在线免费毛片 | 在线三级电影 | 不卡一二三区 | 成人精品免费 | 九九免费观看视频 | 毛片网站在线观看 | 欧美日韩高清在线观看 | 欧美日韩精品一区二区三区四区 | 成人夜晚看av | 国产在线二区 | 中文字幕国产一区 | 精品国产一区二区 | 亚洲精品9999久久久久 | 久久精品国产亚洲一区二区三区 | 欧美在线视频a | 日本激情视频在线播放 |