bug调试-卡片轮播反转漏白边
2015-12-07 00:17
267 查看
bug调试-卡片轮播反转漏白边
项目中做了一个卡片滚动的效果,使用scrollView, 自己写的重用.但是有个bug:顺序滚动没问题,往回滚第三张会漏出白边:
_**
一开始以为是动画没做好:
- (void)refreshVisibleCellAppearance{ if (_minimumPageAlpha == 1.0 && _minimumPageScale == 1.0) { return;//无需更新 } CGFloat offset = _scrollView.contentOffset.x; if (_cells.count > 0) { for (NSInteger i = _visibleRange.location; i < _visibleRange.location + _visibleRange.length; i++) { UIView *cell = [_cells objectAtIndex:i]; CGFloat origin = cell.center.x; CGFloat delta = fabs(origin - _pageSize.width / 2 - offset); CGRect originCellFrame = CGRectMake(_pageSize.width * i, 0, _pageSize.width, _pageSize.height);//如果没有缩小效果的情况下的本该的Frame [UIView beginAnimations:@"CellAnimation" context:nil]; **if (delta < _pageSize.width) { CGFloat inset = _pageSize.width * (1 - _minimumPageScale) * (delta / _pageSize.width) / 2.0; // CGFloat inset = _pageSize.width * (1 - _minimumPageScale) / 2.0 ; cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(inset, 7.5, inset, 7.5)); } else { CGFloat inset = _pageSize.width * (1 - _minimumPageScale) / 2.0 ; cell.frame = UIEdgeInsetsInsetRect(originCellFrame, UIEdgeInsetsMake(inset, 7.5, inset, 7.5));** // 开始以为是这段代码有问题 } [UIView commitAnimations]; } } }
注释掉怀疑的代码仍然不能修正bug
后来关注下面的代码:
{
//计算_visibleRange
CGPoint startPoint = CGPointMake(offset.x - _scrollView.frame.origin.x, offset.y - _scrollView.frame.origin.y); CGPoint endPoint = CGPointMake(startPoint.x + self.bounds.size.width, startPoint.y + self.bounds.size.height); NSInteger startIndex = 0; for (NSInteger i =0; i < [_cells count]; i++) { if (_pageSize.width * (i) > startPoint.x) { startIndex = i; break; } } NSInteger endIndex = startIndex; for (NSInteger i = startIndex; i < [_cells count]; i++) { //如果都不超过则取最后一个 if ((_pageSize.width * (i + 1) < endPoint.x && _pageSize.width * (i + 2) >= endPoint.x) || i+ 2 == [_cells count]) { endIndex = i + 1;//i+2 是以个数,所以其index需要减去1 break; } } //可见页分别向前向后扩展一个,提高效率
// startIndex = MAX(startIndex - 2, 0);
// 我将下面的代码改成 startIndex = MAX(startIndex, 0);发现是这样的情况
// 偏移的图片在正中间了,于是我改成 startIndex = MAX(startIndex - 2, 0);
// 搞定!Ohyeah!
startIndex = MAX(startIndex - 1, 0);
endIndex = MIN(endIndex + 1, [_cells count] - 1);
_visibleRange.location = startIndex;
_visibleRange.length = endIndex - startIndex + 1;
NSLog(@"%ld===========%ld", startIndex, endIndex); for (NSInteger i = startIndex; i <= endIndex; i++) { [self setPageAtIndex:i]; } for (NSInteger i = 0; i < startIndex; i ++) { [self removeCellAtIndex:i]; }
// NSLog(@”=================%@”, _cells);
for (NSInteger i = endIndex + 1; i < [_cells count]; i ++) {
[self removeCellAtIndex:i];
}
}
最终效果:
相关文章推荐
- SourceProvider.getJniDirectories
- Trac 中文语言安装
- 软件 bug 的生命周期
- Firefox2中输入框丢失光标bug的解决方法
- for命令的一些bug分析
- 修正IE下使用CSS属性overflow的bug
- 解决IE6 3像素Bug的css写法
- 跟我学习JScript的Bug与内存管理
- JS注释所产生的bug 即使注释也会执行
- IE本地存储userdata的一个bug说明
- IE在DOM操作有表单控件时的bug
- ie 处理 gif动画 的onload 事件的一个 bug
- IIS6 安全性存在超级BUG,快来看
- Android生存指南之:解Bug策略与思路问题的详解
- shell脚本中case条件控制语句的一个bug分析
- 关于在IE下的一个安全BUG --可用于跟踪用户的系统鼠标位置
- jQuery ajax BUG:object doesn't support this property or method
- ShareSDK造成App崩溃的一个BUG原因分析以及Fix方法
- 关于c语言的一个小bug详解
- JavaScript编程中容易出BUG的几点小知识