今天在解决一个实习生写的代码的bug,表现情况是在切换view的时候由于要对切换过来的view做一个偏移,所以在计算偏移的时候定义了一个CGFloat变量,但没有做初始化,结果在Debug环境下偏移是没有问题的,但在Release环境下就会偏移一个屏幕的高度。
以下是相关部分的代码:
- (CGFloat)setCollectionContentOffset:(CGPoint)offset {
CGFloat boundsH = _momentCollectionView.frame.size.height;
CGFloat contentH = _momentCollectionView.contentSize.height;
CGFloat maxOffset = contentH + collectionOffset - boundsH;
//这行是关键代码
CGFloat moveOffset;
NSLog(@"moveOffset initial value: %f", moveOffset);
if (offset.y > avatarRegionView_origin_height) {
//代码并没有进入这里
offset.y = avatarRegionView_origin_height<maxOffset ? avatarRegionView_origin_height : maxOffset;
moveOffset = avatarRegionView_origin_height-maxOffset;
}
else if (offset.y + boundsH > collectionOffset + contentH) {
//代码也没有进入这里
mo