pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

UIScrollView 無限滾動

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

問題描述

我正在嘗試設置一個無限(水平)滾動的滾動視圖.

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

向前滾動很容易——我已經實現了 scrollViewDidScroll,當 contentOffset 接近尾聲時,我將滾動視圖的 contentsize 放大并在空間中添加更多數據(我將不得不處理稍后會產生的嚴重影響!)

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!)

我的問題是向后滾動 - 計劃是看看我何時接近滾動視圖的開頭,然后當我確實使 contentsize 更大時,移動現有內容,將新數據添加到開頭,然后 -重要的是調整 contentOffset 使視口下的數據保持不變.

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.

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

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);
}

隨著滾動的發生,日志顯示: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

然后,當 pageNumber<4 時(我們即將開始):4479.5000004479.500000

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

太棒了!- 但數字應該會在 4,000 秒內繼續下降,但下一個日志條目顯示: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....

從中斷的地方繼續!

僅作記錄,如果滾動緩慢,日志會顯示: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....

有什么想法嗎????

謝謝

本.

推薦答案

可能是無論在其中設置這些數字,都不會因為您將 contentOffset 設置在其手中而留下深刻印象.所以它只是繼續設置它認為應該是下一個瞬間的 contentOffset - 而不驗證 contentOffset 在此期間是否發生了變化.

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.

我會將 UIScrollView 子類化并將魔法放在 setContentOffset 方法中.根據我的經驗,所有內容偏移更改都通過該方法,即使是內部滾動引起的內容偏移更改.只需在某個時候執行 [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.

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

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".

這篇關于UIScrollView 無限滾動的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

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

相關文檔推薦

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(以編程方式設置 contentOffset 觸發 scrollViewDidScroll)
Photos app-like gap between pages in UIScrollView with pagingEnabled(使用 pagingEnabled 的 UIScrollView 中頁面之間的照片應用程序式間隙)
why UIScrollView is leaving space from top in ios 6 and ios 7(為什么 UIScrollView 在 ios 6 和 ios 7 中從頂部留下空間)
UIScrollView pauses NSTimer while scrolling(UIScrollView 在滾動時暫停 NSTimer)
主站蜘蛛池模板: 档案密集架,移动密集架,手摇式密集架,吉林档案密集架-厂家直销★价格公道★质量保证 | 英语词典_成语词典_日语词典_法语词典_在线词典网 | 高防护蠕动泵-多通道灌装系统-高防护蠕动泵-www.bjhuiyufluid.com慧宇伟业(北京)流体设备有限公司 | 量子管通环-自清洗过滤器-全自动反冲洗过滤器-北京罗伦过滤技术集团有限公司 | 青岛侦探调查_青岛侦探事务所_青岛调查事务所_青岛婚外情取证-青岛狄仁杰国际侦探公司 | EDLC超级法拉电容器_LIC锂离子超级电容_超级电容模组_软包单体电容电池_轴向薄膜电力电容器_深圳佳名兴电容有限公司_JMX专注中高端品牌电容生产厂家 | 双能x射线骨密度检测仪_dxa骨密度仪_双能x线骨密度仪_品牌厂家【品源医疗】 | 气象监测系统_气象传感器_微型气象仪_气象环境监测仪-山东风途物联网 | 证券新闻,热播美式保罗1984第二部_腾讯1080p-仁爱影院 | 安徽净化工程设计_无尘净化车间工程_合肥净化实验室_安徽创世环境科技有限公司 | 法兰连接型电磁流量计-蒸汽孔板节流装置流量计-北京凯安达仪器仪表有限公司 | 钣金加工厂家-钣金加工-佛山钣金厂-月汇好 | 京马网,京马建站,网站定制,营销型网站建设,东莞建站,东莞网站建设-首页-京马网 | 耐磨陶瓷管道_除渣器厂家-淄博浩瀚陶瓷科技有限公司 | 电镀整流器_微弧氧化电源_高频电解电源_微弧氧化设备厂家_深圳开瑞节能 | 聚合氯化铝厂家-聚合氯化铝铁价格-河南洁康环保科技 | 中细软知识产权_专业知识产权解决方案提供商 | 茶楼装修设计_茶馆室内设计效果图_云臻轩茶楼装饰公司 | 实验室装修_实验室设计_实验室规划设计- 上海广建净化工程公司 | 长江船运_国内海运_内贸船运_大件海运|运输_船舶运输价格_钢材船运_内河运输_风电甲板船_游艇运输_航运货代电话_上海交航船运 | 空气能暖气片,暖气片厂家,山东暖气片,临沂暖气片-临沂永超暖通设备有限公司 | 拉力机-万能试验机-材料拉伸试验机-电子拉力机-拉力试验机厂家-冲击试验机-苏州皖仪实验仪器有限公司 | 巩义市科瑞仪器有限公司| 背压阀|减压器|不锈钢减压器|减压阀|卫生级背压阀|单向阀|背压阀厂家-上海沃原自控阀门有限公司 本安接线盒-本安电路用接线盒-本安分线盒-矿用电话接线盒-JHH生产厂家-宁波龙亿电子科技有限公司 | 【法利莱住人集装箱厂家】—活动集装箱房,集装箱租赁_大品牌,更放心 | 陕西自考报名_陕西自学考试网 | 兰州UPS电源,兰州山特UPS-兰州万胜商贸| 包塑软管|金属软管|包塑金属软管-闵彬管业 | 北钻固控设备|石油钻采设备-石油固控设备厂家 | 北京发电机出租_发电机租赁_北京发电机维修 - 河北腾伦发电机出租 | 机器视觉检测系统-视觉检测系统-机器视觉系统-ccd检测系统-视觉控制器-视控一体机 -海克易邦 | DDoS安全防护官网-领先的DDoS安全防护服务商 | 上海小程序开发-上海小程序制作公司-上海网站建设-公众号开发运营-软件外包公司-咏熠科技 | 神马影院-实时更新秒播| 翅片管散热器价格_钢制暖气片报价_钢制板式散热器厂家「河北冀春暖气片有限公司」 | 楼承板设备-楼承板成型机-免浇筑楼承板机器厂家-捡来 | 断桥铝破碎机_铝合金破碎机_废铁金属破碎机-河南鑫世昌机械制造有限公司 | 河南彩印编织袋,郑州饲料编织袋定制,肥料编织袋加工厂-盛军塑业 河南凯邦机械制造有限公司 | 亚克力制品定制,上海嘉定有机玻璃加工制作生产厂家—官网 | 书法培训-高考书法艺考培训班-山东艺霖书法培训凭实力挺进央美 | 立刷【微电签pos机】-嘉联支付立刷运营中心 |