来自 frame.height 的 CGFloat 值

问题描述

我遇到了一些非常愚蠢的事情:无法使用从视图大小获取的 CGFloat 进行操作。有人可以帮我解释一下我做错了什么:

代码如下:

 CGFloat containedViewHeight = self.containedView_.frame.size.height;
 NSLog(@"========================   containedViewHeight  ================= %d",containedViewHeight);
 NSLog(@"========================   containedViewHeight1  ================= %d",self.containedView_.frame.size.height);

这是我得到的:

 ========================   containedViewHeight  ================= 1587588653

 ========================   containedViewHeight1  ================= 775

值“775”看起来不错,但我无法将其保存到任何变量中。 我也尝试过这样的事情:

int offset = containerHeight - (int)(self.containedView_.frame.size.height);

(int)(self.containedView_.frame.size.height) 总是等于 0

请告诉我哪里出了问题...

*** 如果我使用 %f 作为内部日志而不是我得到的:

========================   containedViewHeight  ================= 0.000000
=======================   containedViewHeight1  ================= 0.000000

解决方法

您将 %d 传递给 NSLog 的字符串格式。这将 containedViewHeight 解释为整数。你想要%f

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...