简体   繁体   English

CGFloat值分配错误

[英]CGFloat Value Assignment Error

I am having a strange issue working on a new iOS (v7 SDK) app while working with CGFloat. 在使用CGFloat时,我在使用新的iOS(v7 SDK)应用程序时遇到了一个奇怪的问题。 A test photograph with dimensions 2448w X 3264h (saved in photographSize) is creating errors when I try to get its width and save it to a CGFloat. 当我试图获得其宽度并将其保存到CGFloat时,尺寸为2448w X 3264h(保存在photographSize中)的测试照片会产生错误。 Here is how the code looks: 以下是代码的外观:

@property (weak, nonatomic) IBOutlet UIImageView *Photograph;
...
UIImage *photographImage = Photograph.image;
CGSize photographSize = [photographImage size];
...
CGFloat photoScale = photographSize.width;

photoScale is incorrectly being assigned the value 7.6500001 instead of 2448. What gives? photoScale被错误地分配值7.6500001而不是2448.什么给出了什么? Is this a sign of over/underflow happening? 这是上溢/下溢发生的迹象吗? I have verified the values in photographSize to be 2448w X 3264h in the debugger. 我已经在调试器中验证了photographSize中的值为2448w X 3264h。 Also, Photograph is a UIImageView. 此外,Photograph是一个UIImageView。

Thanks, I will monitor this thread throughout the day. 谢谢,我将全天监控这个帖子。

Maybe a mistake? 也许是个错误? Should be 应该

CGSize photographScaledSize = Photograph.bounds.size;
CGFloat photoScale = photographScaledSize.width;
                               ^^^^^^

Update source code like below 更新源代码如下

CGFloat photoScale = photographSize.width;

to

CGFloat photoScale = photographScaledSize.width;

I used you code with my image and its working me fine. 我用你的代码和我的形象一起使用它很好。 May be there is issue at assign image to UIImage *photographImage 将图像分配给UIImage *photographImage可能存在问题

    UIImage *photographImage = [UIImage imageNamed:@"7_normal.png"];
    CGSize photographSize = [photographImage size];
    CGFloat photoScale = photographSize.width;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM