Skip to content

Commit ceb8306

Browse files
committed
把全局的 flatf 重命名为 flat,并将参数类型从 float 改为 CGFloat,从而修复 UIImage 绘制图片时由于精度不足导致可能尺寸不正确的 bug
1 parent 571f0d0 commit ceb8306

6 files changed

Lines changed: 17 additions & 17 deletions

File tree

qmuidemo/Modules/Common/Controllers/QDCommonGridViewController.m

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,21 +45,21 @@ - (void)viewDidLayoutSubviews {
4545

4646
if (CGRectGetWidth(self.view.bounds) <= [QMUIHelper screenSizeFor55Inch].width) {
4747
self.gridView.columnCount = 3;
48-
CGFloat itemWidth = flatf(CGRectGetWidth(self.scrollView.bounds) / self.gridView.columnCount);
48+
CGFloat itemWidth = flat(CGRectGetWidth(self.scrollView.bounds) / self.gridView.columnCount);
4949
self.gridView.rowHeight = itemWidth;
5050
} else {
51-
CGFloat minimumItemWidth = flatf([QMUIHelper screenSizeFor55Inch].width / 3.0);
52-
CGFloat maximumItemWidth = flatf(CGRectGetWidth(self.view.bounds) / 5.0);
53-
CGFloat freeSpacingWhenDisplayingMinimumCount = CGRectGetWidth(self.scrollView.bounds) / maximumItemWidth - floorf(CGRectGetWidth(self.scrollView.bounds) / maximumItemWidth);
54-
CGFloat freeSpacingWhenDisplayingMaximumCount = CGRectGetWidth(self.scrollView.bounds) / minimumItemWidth - floorf(CGRectGetWidth(self.scrollView.bounds) / minimumItemWidth);
51+
CGFloat minimumItemWidth = flat([QMUIHelper screenSizeFor55Inch].width / 3.0);
52+
CGFloat maximumItemWidth = flat(CGRectGetWidth(self.view.bounds) / 5.0);
53+
CGFloat freeSpacingWhenDisplayingMinimumCount = CGRectGetWidth(self.scrollView.bounds) / maximumItemWidth - floor(CGRectGetWidth(self.scrollView.bounds) / maximumItemWidth);
54+
CGFloat freeSpacingWhenDisplayingMaximumCount = CGRectGetWidth(self.scrollView.bounds) / minimumItemWidth - floor(CGRectGetWidth(self.scrollView.bounds) / minimumItemWidth);
5555
if (freeSpacingWhenDisplayingMinimumCount < freeSpacingWhenDisplayingMaximumCount) {
5656
// 按每行最少item的情况来布局的话,空间利用率会更高,所以按最少item来
57-
self.gridView.columnCount = floorf(CGRectGetWidth(self.scrollView.bounds) / maximumItemWidth);
58-
CGFloat itemWidth = floorf(CGRectGetWidth(self.scrollView.bounds) / self.gridView.columnCount);
57+
self.gridView.columnCount = floor(CGRectGetWidth(self.scrollView.bounds) / maximumItemWidth);
58+
CGFloat itemWidth = floor(CGRectGetWidth(self.scrollView.bounds) / self.gridView.columnCount);
5959
self.gridView.rowHeight = itemWidth;
6060
} else {
61-
self.gridView.columnCount = floorf(CGRectGetWidth(self.scrollView.bounds) / minimumItemWidth);
62-
CGFloat itemWidth = floorf(CGRectGetWidth(self.scrollView.bounds) / self.gridView.columnCount);
61+
self.gridView.columnCount = floor(CGRectGetWidth(self.scrollView.bounds) / minimumItemWidth);
62+
CGFloat itemWidth = floor(CGRectGetWidth(self.scrollView.bounds) / self.gridView.columnCount);
6363
self.gridView.rowHeight = itemWidth;
6464
}
6565
}
@@ -125,7 +125,7 @@ - (void)layoutSubviews {
125125
}
126126

127127
CGSize contentSize = CGSizeMake(CGRectGetWidth(self.bounds) - UIEdgeInsetsGetHorizontalValue(self.contentEdgeInsets), CGRectGetHeight(self.bounds) - UIEdgeInsetsGetVerticalValue(self.contentEdgeInsets));
128-
CGPoint center = CGPointMake(flatf(self.contentEdgeInsets.left + contentSize.width / 2), flatf(self.contentEdgeInsets.top + contentSize.height / 2));
128+
CGPoint center = CGPointMake(flat(self.contentEdgeInsets.left + contentSize.width / 2), flat(self.contentEdgeInsets.top + contentSize.height / 2));
129129

130130
self.imageView.center = CGPointMake(center.x, center.y - 12);
131131

qmuidemo/Modules/Common/Utils/UIImageEffects.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ + (UIImage*)imageByApplyingBlurToImage:(UIImage*)inputImage withRadius:(CGFloat)
236236
NSUInteger matrixSize = sizeof(floatingPointSaturationMatrix)/sizeof(floatingPointSaturationMatrix[0]);
237237
int16_t saturationMatrix[matrixSize];
238238
for (NSUInteger i = 0; i < matrixSize; ++i) {
239-
saturationMatrix[i] = (int16_t)roundf(floatingPointSaturationMatrix[i] * divisor);
239+
saturationMatrix[i] = (int16_t)round(floatingPointSaturationMatrix[i] * divisor);
240240
}
241241
vImageMatrixMultiply_ARGB8888(inputBuffer, outputBuffer, saturationMatrix, divisor, NULL, NULL, kvImageNoFlags);
242242

qmuidemo/Modules/Demos/About/QDAboutViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ - (void)viewDidLayoutSubviews {
7979
self.scrollView.frame = CGRectSetHeight(self.view.bounds, CGRectGetHeight(self.view.bounds) - tabBarHeight);
8080

8181
if (IS_IPHONE && IS_LANDSCAPE) {
82-
CGFloat leftWidth = flatf(CGRectGetWidth(self.scrollView.bounds) / 2);
82+
CGFloat leftWidth = flat(CGRectGetWidth(self.scrollView.bounds) / 2);
8383
CGFloat rightWidth = CGRectGetWidth(self.scrollView.bounds) - leftWidth;
8484

8585
CGFloat leftHeight = CGRectGetHeight(self.logoImageView.frame) + versionLabelMarginTop + CGRectGetHeight(self.versionLabel.frame);

qmuidemo/Modules/Demos/Lab/Animation/QDActivityIndicator.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ - (CAAnimationGroup *)groupAnimationWithIndex:(NSInteger)index {
138138
@[@0.0f, @(20.0f / 90.0f), @(35.0f / 90.0f), @((54.0f) / 90.0f), @(70.0f / 90.0f), @1.0f]];
139139

140140
CALayer *line = _lines[index];
141-
CGFloat x = floorf((CGRectGetWidth(self.bounds) / 2 - lineWidth) / 2 + CGRectGetWidth(self.bounds) / 2 * (index / 3) + (index / 3 > 0 ? 0 : 1));
142-
CGFloat y = floorf(lineBaseY + (lineHeight + lineSpacing) * (index % 3));
141+
CGFloat x = floor((CGRectGetWidth(self.bounds) / 2 - lineWidth) / 2 + CGRectGetWidth(self.bounds) / 2 * (index / 3) + (index / 3 > 0 ? 0 : 1));
142+
CGFloat y = floor(lineBaseY + (lineHeight + lineSpacing) * (index % 3));
143143
line.frame = CGRectMake(x, y, 0, lineHeight);
144144

145145
NSArray *keyTimes = keyTimesForLines[index];

qmuidemo/Modules/Demos/UIKit/QDImageViewController.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ - (CGFloat)generateExampleViewForAverageColor {
189189

190190
UIImageView *originImageView = [[UIImageView alloc] initWithImage:UIImageMake(@"image0")];
191191
originImageView.contentMode = UIViewContentModeScaleAspectFit;
192-
originImageView.frame = CGRectMake(0, minY, contentWidth, flatf(contentWidth * originImageView.image.size.height / originImageView.image.size.width));
192+
originImageView.frame = CGRectMake(0, minY, contentWidth, flat(contentWidth * originImageView.image.size.height / originImageView.image.size.width));
193193
[self.contentScrollView addSubview:originImageView];
194194
minY = CGRectGetMaxY(originImageView.frame) + 16;
195195

@@ -274,7 +274,7 @@ - (CGFloat)generateExampleViewForImageWithAlpha {
274274

275275
UIImage *imageAddedAlpha = [originImageView.image qmui_imageWithAlpha:.5];
276276
CGSize imageViewSize = CGSizeMake(CGRectGetWidth(originImageView.frame) - 20, 0);
277-
imageViewSize.height = flatf(imageViewSize.width * CGRectGetHeight(originImageView.frame) / CGRectGetWidth(originImageView.frame));
277+
imageViewSize.height = flat(imageViewSize.width * CGRectGetHeight(originImageView.frame) / CGRectGetWidth(originImageView.frame));
278278

279279
UIImageView *afterImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, minY, imageViewSize.width, imageViewSize.height)];
280280
afterImageView.contentMode = originImageView.contentMode;

qmuidemo/Modules/Demos/UIKit/QDTabBarItemViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ - (QMUILabel *)generateMessageNumberLabelWithInteger:(NSInteger)integer inView:(
9393
CGFloat diameter = fmaxf(CGRectGetWidth(numberLabel.bounds), CGRectGetHeight(numberLabel.bounds));
9494
numberLabel.frame = CGRectMake(CGRectGetMinX(numberLabel.frame), CGRectGetMinY(numberLabel.frame), diameter, diameter);
9595
}
96-
numberLabel.layer.cornerRadius = flatf(CGRectGetHeight(numberLabel.bounds) / 2.0);
96+
numberLabel.layer.cornerRadius = flat(CGRectGetHeight(numberLabel.bounds) / 2.0);
9797
return numberLabel;
9898
}
9999

0 commit comments

Comments
 (0)