1.不同预览模式
2.计算出缩放比
3.固定滚动偏移
关键代码:
overview:
ratioW = getChildRect().width / getParentRect().width
ratioH = getChildRect().height / getParentRect().height
maxRatio = max(ratioW, ratioH)
if(maxRatio < 1)
return 1
else
return 1/maxRatio
oldViewCenter = viewCenterOffset
real:
if(bInit) { // 重置
if(childOutline.height < parentOutline.height)
oldViewCenter.fY = viewCenterOffset.fY;
else
oldViewCenter.fY = viewCenterOffset.fY + (childOutline.height - parentOutline.height) / 2; //顶部对齐
} else { // 滚动后拉伸
if(refParentOutline.top >= refChildOutline.top) //上次就无溢出
oldViewCenter.fY = viewCenterOffset.fY + (childOutline.height - parentOutline.height) / 2; //顶部对齐
else {
overflowLen = refParentOutline.top - refChildOutline.top //溢出长度
if(childOutline.height - overflowLen <= parentOutline.height) //溢出后下面留白
oldViewCenter.fY = parentOutline.bottom - childOutline.bottom // 底部对齐
else
oldViewCenter.fY = parentOutline.top - overflowLen - childOutline.top // 顶部溢出对齐
}
}