tableView是iOS中使用最多的控件之一将塑,所以優(yōu)化tableView也是iOS開發(fā)必做的一件事情禾唁。想要知道列表的流暢度曙强,只靠肉眼來判斷還是不能深入知道列表的流暢度處于一個(gè)什么階段救湖。所以拣播,我們可以借助一些工具來查看列表滑動(dòng)時(shí)細(xì)微的幀數(shù)變化晾咪,而YYFPSLabel就是一個(gè)使用簡(jiǎn)單,結(jié)果易見的工具贮配。
這是我在項(xiàng)目中使用的情況:
YYFPSLabel.PNG
下面我們就看看怎么使用YYFPSLabel
1.YYFPSLabel 主要有兩個(gè)文件 谍倦,一是:YYFPSLabel 二是:YYWeakProxy
2.這兩個(gè)文件可以從YYKit中找到,如果你的項(xiàng)目中沒有使用到Y(jié)YKit或者YYText的話泪勒,直接從YYKIt里面拿出來肯定是會(huì)報(bào)錯(cuò)的昼蛀,為了給大家提供便利,我已經(jīng)將這兩個(gè)文件抽出來了圆存,并且處理了報(bào)錯(cuò)的地方叼旋,大家可以直接從百度云下載這兩個(gè)文件,拖進(jìn)項(xiàng)目中就可以使用了 。 下載地址:下載地址 提取碼:kneh
3.在viewDidLoad方法里面 添加代碼(初始化label,并添加到view上)
_fpsLabel = [YYFPSLabel new];
[_fpsLabel sizeToFit];
_fpsLabel.frame = CGRectMake(80, 200, 80, 20);
_fpsLabel.alpha = 0;
_fpsLabel.textColor = [UIColor whiteColor];
[self.view addSubview:_fpsLabel];
4.在scrollview的代理方法里面改變FPSLabel的透明度
- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
if (_fpsLabel.alpha == 0) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
_fpsLabel.alpha = 1;
} completion:NULL];
}
}
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {
if (!decelerate) {
if (_fpsLabel.alpha != 0) {
[UIView animateWithDuration:1 delay:2 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
_fpsLabel.alpha = 0;
} completion:NULL];
}
}
}
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
if (_fpsLabel.alpha != 0) {
[UIView animateWithDuration:1 delay:2 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
_fpsLabel.alpha = 0;
} completion:NULL];
}
}
- (void)scrollViewDidScrollToTop:(UIScrollView *)scrollView {
if (_fpsLabel.alpha == 0) {
[UIView animateWithDuration:0.3 delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
_fpsLabel.alpha = 1;
} completion:^(BOOL finished) {
}];
}
}
到此猿推,YYFPSLabel就就添加完成了,使用起來還是非常簡(jiǎn)便的鸠天,非常感謝YYKit的作者為我們提供的便利。