diwu / runloopworkdistribution Goto Github PK
View Code? Open in Web Editor NEWiOS Fast Scrolling with RunLoop Work Distribution
License: MIT License
iOS Fast Scrolling with RunLoop Work Distribution
License: MIT License
我想问一下:对于这种优化,我们可以看到在tracking模式下,cell上面一片空白(或者你放一个比较小的背景占位图),但是当滑动停止,处于default模式了,这个时候渲染图片了,你会发现之前的空白(或占位图)会被填充,感觉视觉上的效果蛮差的。例如我们希望可以获得微信朋友圈或微博那样的体验,有没有更好的优化方案呢?我们抛开高度缓存这些角度,其他角度怎么优化呢?
@implementation DWURunLoopWorkDistribution
- (instancetype)init
{
if ((self = [super init])) {
_maximumQueueLength = 30;
_tasks = [NSMutableArray array];
_tasksKeys = [NSMutableArray array];
// _timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(_timerFiredMethod:) userInfo:nil repeats:YES];
// 如果不加延迟会导致启动黑屏, 可能是由于启动 App 时, 无法正常 Mode 切换的原因;
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSRunLoop* runLoop = [NSRunLoop currentRunLoop];
[runLoop addPort:[NSMachPort port] forMode:NSDefaultRunLoopMode];
[runLoop run];
});
}
return self;
}
使用kCFRunLoopCommonModes替代kCFRunLoopDefaultMode是不是会更好些呢,这样在滚动的时候也能进行加载。还是说有其他我没想到的问题?
我将这个Demo转换成给collectionview 使用,然后从网络上下载图片,发现在上下滚动collectionview的过程中,原本在item = 1位置的图片,变到item = 2的位置,item = 2 的图片变到item = 1 的位置,也就是两个图片互相交换了位置,然后再滑动collectionview的时候又互相交换位置了,一直滚动就一直重复出现这个问题。
如果已进入页面不滑动页面就不会显示图片,
占用内存太大了。
就一个页面,500多M
为什么我认为,这个不是每次RunLoop结束前执行一次任务,而且在一次RunLoop结束的前下执行了所有在tasks中的任务?
如果只执行一次的话,那么RunLoop休眠,页面保持静止,应该只加载一张图的啊。
while (result == NO && runLoopWorkDistribution.tasks.count) {
DWURunLoopWorkDistributionUnit unit = runLoopWorkDistribution.tasks.firstObject;
result = unit();
[runLoopWorkDistribution.tasks removeObjectAtIndex:0];
[runLoopWorkDistribution.tasksKeys removeObjectAtIndex:0];
}
这个不是一次执行完的吗?
点个赞
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.