Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

百分比布局下,设置小数比例无效! #72

Open
Wuou opened this issue May 29, 2024 · 3 comments
Open

百分比布局下,设置小数比例无效! #72

Wuou opened this issue May 29, 2024 · 3 comments

Comments

@Wuou
Copy link

Wuou commented May 29, 2024

百分比布局下,percentOfRow设置小数比例无效!
例如:
case 0:
return 0.39;
case 1:
return 0.61;

宽度不会按如上比例分配

@Wuou
Copy link
Author

Wuou commented May 29, 2024

看了源代码,实际浮点数判断相等有问题,但是作者保留了0.1的误差值,作为一行的判断标准。
image

实际可以更精确点:

  • (BOOL)isGreaterThanOrEqual:(CGFloat)num compared:(CGFloat)compared {
    // 对于float类型,如果是double类型请使用DBL_EPSILON
    // 减去一个很小的容差值来确保精度问题不会影响判断
    return num >= (compared - FLT_EPSILON);
    }

判断是否等于1:
fabs(num - 1.0) < FLT_EPSILON

@czl0325
Copy link
Owner

czl0325 commented May 30, 2024

奇怪,我测试了原来的代码和你改的代码。两者出来的效果是一致的

@Wuou
Copy link
Author

Wuou commented Jun 14, 2024

奇怪,我测试了原来的代码和你改的代码。两者出来的效果是一致的

。。我这边改了,布局就正常了,这里主要还是判断浮点数相等问题,会不会是不同系统版本有点区别。。。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants