floor-round-ceil
英文意思:floor:地板 round:变圆 ceil:天花板
因为项目里面 6p计算scrollView分页 和 滑动到顶部出现误差 所以这里需要重新审视一下 这些系统函数
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
NSInteger index = scrollView.contentOffset.x / self.contentBG.width;
NSLog(@"scrollView.contentOffset.x:%f,self.contentBG.width:%f,%ld",scrollView.contentOffset.x,self.contentBG.width,index);
CGFloat tmpOffsetX = scrollView.contentOffset.x / self.contentBG.width;
NSLog(@"%f",tmpOffsetX);
index = floor(tmpOffsetX);
NSLog(@"index:%ld,floor(tmpOffsetX):%f",index,floor(tmpOffsetX));
index = round(tmpOffsetX);
NSLog(@"index:%ld,round(tmpOffsetX):%f",index,round(tmpOffsetX));
index = ceil(tmpOffsetX);
NSLog(@"index:%ld,ceil(tmpOffsetX):%f",index,ceil(tmpOffsetX));
if (1 == 1.000000) {
NSLog(@"6个0");
}
if (1 == 1.00) {
NSLog(@"2个0");
}
}
scrollView.contentOffset.x:376.333333,self.contentBG.width:376.464000,0
0.999653
index:0,floor(tmpOffsetX):0.000000
index:1,round(tmpOffsetX):1.000000
index:1,ceil(tmpOffsetX):1.000000
6个0
2个0
***以上出现误差 这时候分页索引应该用四舍五入round来取 *
- floor
向下取整 按小的来 负数也是 - round
四舍五入 - ceil
向上取整 按大的来 负数也是 - fabs 绝对值
网友评论