Giter VIP home page Giter VIP logo

Comments (5)

lixiang1994 avatar lixiang1994 commented on July 16, 2024 1

我将整个计算部分暴露出来可以让使用者重写, 就是考虑到了每个人的情景不同, 有些人是根据宽度方式计算, 但有些人确不是. 我不能去限制他们的计算规则, 我觉得我应该提供最通用的API, 你说的枚举类型应该是在我这个的上一层的封装, 我也在考虑是我来封装这一层还是由使用者自己按照需要封装.

其实目前这种计算处理只需要设置一次即可, 如果你觉得代码过多 可以考虑将他们放入一个func中, 很高兴能收到你的建议, 容我再考虑一下. 😄

from autoinch.

lixiang1994 avatar lixiang1994 commented on July 16, 2024

这一点是可以的, 只不过我没有在文档中写出

通过源码可以看到我是通过两个静态变量的闭包来进行计算处理的, 默认是基于375按照比例计算的

public enum Auto {
    
    /// 转换 用于数值的等比例计算 如需自定义可重新赋值
    public static var conversion: ((Double) -> Double) = { (origin) in
        guard UIDevice.current.userInterfaceIdiom == .phone else {
            return origin
        }
        
        let base = 375.0 
        let screenWidth = Double(UIScreen.main.bounds.width)
        let screenHeight = Double(UIScreen.main.bounds.height)
        let width = min(screenWidth, screenHeight)
        return origin * (width / base)
    }
    
    /// 适配 用于可视化等比例计算 如需自定义可重新赋值
    public static var adaptation: ((CGFloat) -> CGFloat) = { (origin) in
        return origin.auto()
    }
}

可以在启动时 为这个静态变量赋值一个新的闭包.

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        Auto.conversion = { (origin) in
            guard UIDevice.current.userInterfaceIdiom == .phone else {
                return origin
            }
            
            let base = 414.0
            let screenWidth = Double(UIScreen.main.bounds.width)
            let screenHeight = Double(UIScreen.main.bounds.height)
            let width = min(screenWidth, screenHeight)
            return origin * (width / base)
        }
        
        return true
    }

from autoinch.

manondidi avatar manondidi commented on July 16, 2024

能否简便点,不要让业务层写这么多代码

from autoinch.

manondidi avatar manondidi commented on July 16, 2024

我认为最好不要让用户配置这种数字,而是初始化的时候传入一个枚举,告诉你UI给的设计稿是基于哪个设备 而不是传入数字或者传一个闭包,要简化业务层的代码。

from autoinch.

manondidi avatar manondidi commented on July 16, 2024

这块改善了吗

from autoinch.

Related Issues (11)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.