Ai
3 Star 0 Fork 0

Gitee 极速下载/fastimagecache

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/path/FastImageCache
克隆/下载
FICDTableView.m 3.51 KB
一键复制 编辑 原始数据 按行查看 历史
//
// FICDTableView.m
// FastImageCacheDemo
//
// Copyright (c) 2013 Path, Inc.
// See LICENSE for full license agreement.
//
#import "FICDTableView.h"
#pragma mark Class Extension
@interface FICDTableView () {
CADisplayLink *_displayLink;
NSInteger _framesInLastInterval;
CFAbsoluteTime _lastLogTime;
NSInteger _totalFrames;
NSTimeInterval _scrollingTime;
CGFloat _averageFPS;
}
@property (nonatomic, assign, readwrite) CGFloat averageFPS;
@end
#pragma mark
@implementation FICDTableView
@synthesize averageFPS = _averageFPS;
#pragma mark - Object Lifecycle
- (void)dealloc {
[_displayLink invalidate];
}
- (void)didMoveToWindow {
if ([self window] != nil) {
[self _scrollingStatusDidChange];
} else {
[_displayLink invalidate];
_displayLink = nil;
}
}
#pragma mark - Monitoring Scrolling Performance
- (void)resetScrollingPerformanceCounters {
_framesInLastInterval = 0;
_lastLogTime = CFAbsoluteTimeGetCurrent();
_scrollingTime = 0;
_totalFrames = 0;
}
- (void)_scrollingStatusDidChange {
NSString *currentRunLoopMode = [[NSRunLoop currentRunLoop] currentMode];
BOOL isScrolling = [currentRunLoopMode isEqualToString:UITrackingRunLoopMode];
[NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(_scrollingStatusDidChange) object:nil];
if (isScrolling) {
if (_displayLink == nil) {
_displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(_screenDidUpdateWhileScrolling:)];
[_displayLink addToRunLoop:[NSRunLoop currentRunLoop] forMode:UITrackingRunLoopMode];
}
_framesInLastInterval = 0;
_lastLogTime = CFAbsoluteTimeGetCurrent();
[_displayLink setPaused:NO];
// Let us know when scrolling has stopped
[self performSelector:@selector(_scrollingStatusDidChange) withObject:nil afterDelay:0 inModes:[NSArray arrayWithObject:NSDefaultRunLoopMode]];
} else {
[_displayLink setPaused:YES];
// Let us know when scrolling begins
[self performSelector:@selector(_scrollingStatusDidChange) withObject:nil afterDelay:0 inModes:[NSArray arrayWithObject:UITrackingRunLoopMode]];
}
}
- (void)_screenDidUpdateWhileScrolling:(CADisplayLink *)displayLink {
CFAbsoluteTime currentTime = CFAbsoluteTimeGetCurrent();
if (!_lastLogTime) {
_lastLogTime = currentTime;
}
CGFloat delta = currentTime - _lastLogTime;
if (delta >= 1) {
_scrollingTime += delta;
_totalFrames += _framesInLastInterval;
NSInteger lastFPS = (NSInteger)rintf((CGFloat)_framesInLastInterval / delta);
CGFloat averageFPS = (CGFloat)(_totalFrames / _scrollingTime);
[self setAverageFPS:averageFPS];
static dispatch_queue_t __dispatchQueue = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
__dispatchQueue = dispatch_queue_create("com.path.FastImageCacheDemo.ScrollingPerformanceMeasurement", 0);
});
// We don't want the logging of scrolling performance to be able to impact the scrolling performance,
// so move both the logging and the string formatting onto a GCD serial queue.
dispatch_async(__dispatchQueue, ^{
NSLog(@"*** FIC Demo: Last FPS = %ld, Average FPS = %.2f", (long)lastFPS, averageFPS);
});
_framesInLastInterval = 0;
_lastLogTime = currentTime;
} else {
_framesInLastInterval++;
}
}
@end
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/fastimagecache.git
git@gitee.com:mirrors/fastimagecache.git
mirrors
fastimagecache
fastimagecache
master

搜索帮助