gpt4 book ai didi

iPhone SDK 屏幕尺寸使用相似的语法返回不同的结果

转载 作者:行者123 更新时间:2023-12-03 20:57:55 25 4
gpt4 key购买 nike

我是 iPhone 版 Objective C 的新手。我尝试使用以下代码来获取屏幕尺寸,但是下面的代码返回两个不同的结果:

CGRect screenRect = [UIScreen mainScreen].bounds;
NSLog(@"width: %d", screenRect.size.width);
NSUInteger width = [UIScreen mainScreen].bounds.size.width;
NSUInteger height = [UIScreen mainScreen].bounds.size.height;
NSLog(@"width: %d", width);

第一个 NSLog 输出 0,而最后一个输出 320。为什么它们不同?和指针有关系吗?请帮忙。

最佳答案

%d 表示小数,并且您正在尝试打印 float 。尝试一下

CGRect screenRect = [UIScreen mainScreen].bounds; 
NSLog(@"width: %f", screenRect.size.width);
float width = [UIScreen mainScreen].bounds.size.width;
NSLog(@"width: %f", width);

关于iPhone SDK 屏幕尺寸使用相似的语法返回不同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3581406/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com