Google Chrome 设备工具栏原理

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   // 顶部溢出对齐
            }

        }


创作不易,小小的支持一下吧!

相关推荐

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-05-15 21:12:06       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-05-15 21:12:06       100 阅读
  3. 在Django里面运行非项目文件

    2024-05-15 21:12:06       82 阅读
  4. Python语言-面向对象

    2024-05-15 21:12:06       91 阅读

热门阅读

  1. Linux函数

    2024-05-15 21:12:06       28 阅读
  2. nvr国标sip端口信息异常的处理

    2024-05-15 21:12:06       33 阅读
  3. SpringBoot+Mock Mvc测试web接口增删改查、导入导出

    2024-05-15 21:12:06       30 阅读
  4. 微信小程序更新日志

    2024-05-15 21:12:06       32 阅读
  5. 设计模式之——单例模式

    2024-05-15 21:12:06       34 阅读
  6. android设计模式-单例模式

    2024-05-15 21:12:06       38 阅读
  7. 【设计模式】单例模式-学习记录

    2024-05-15 21:12:06       34 阅读
  8. redis中的大key问题

    2024-05-15 21:12:06       28 阅读
  9. Android Studio实现简易音乐播放器(期末作业)

    2024-05-15 21:12:06       33 阅读
  10. Android security知识点总结

    2024-05-15 21:12:06       26 阅读