Comments (5)
我将整个计算部分暴露出来可以让使用者重写, 就是考虑到了每个人的情景不同, 有些人是根据宽度方式计算, 但有些人确不是. 我不能去限制他们的计算规则, 我觉得我应该提供最通用的API, 你说的枚举类型应该是在我这个的上一层的封装, 我也在考虑是我来封装这一层还是由使用者自己按照需要封装.
其实目前这种计算处理只需要设置一次即可, 如果你觉得代码过多 可以考虑将他们放入一个func中, 很高兴能收到你的建议, 容我再考虑一下.
from autoinch.
这一点是可以的, 只不过我没有在文档中写出
通过源码可以看到我是通过两个静态变量的闭包来进行计算处理的, 默认是基于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.
能否简便点,不要让业务层写这么多代码
from autoinch.
我认为最好不要让用户配置这种数字,而是初始化的时候传入一个枚举,告诉你UI给的设计稿是基于哪个设备 而不是传入数字或者传一个闭包,要简化业务层的代码。
from autoinch.
这块改善了吗
from autoinch.
Related Issues (11)
- 楼主出品,必属精品 顶一个🎉 HOT 2
- 希望作者能支持一下SPM进行管理 HOT 3
- 问个关于像素对齐的问题 HOT 2
- 计算属性? HOT 1
- 希望更具有语义化 HOT 5
- 希望可以对Carthage进行支持 HOT 2
- 有人知道有类似的OC库吗,或者作者出个OC版吗 HOT 3
- 您好,请问支持ipad适配吗? HOT 2
- 有个疑问,如果设计图是iPhoneX的,如何适配非刘海屏(6,7,8等) HOT 2
- 作者能做一个OC的库吗
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from autoinch.