- objective-c - iOS 5 : Can you override UIAppearance customisations in specific classes?
- iphone - 如何将 CGFontRef 转换为 UIFont?
- ios - 以编程方式关闭标记的信息窗口 google maps iOS
- ios - Xcode 5 - 尝试验证存档时出现 "No application records were found"
考虑这样的布局代码:
CGFloat descriptionHeight = // height of a paragraph of text with zero or more words;
CGFloat imageHeight = // height of an image;
CGFloat yCoordinateOfSomeOtherView = fmax(descriptionHeight, imageHeight) + 5.0f;
第三行应该如何重写以支持 64 位 iOS 设备?
(当前代码没有考虑yCoordinateOfSomeOtherView
是float
还是double
。)
几个选项(我不确定哪个最好):
#if defined(__LP64__) && __LP64__
#define cgfmax(x,y) fmaxf(x,y)
#else
#define cgfmax(x,y) fmax(x,y)
#endif
然后我可以将 fmax
替换为 cgfmax
。
tgmath.h
This Stack Overflow answer从 2011 年开始,建议将 math.h
替换为 tgmath.h
。这将 fmax
的实现替换为在每个参数上调用 __typeof__
并返回 fmax
或 fmaxf
的实现,具体取决于参数类型。
由于 CGFloats 与布局相关,将 float
存储到 double
中可能导致的数据丢失通常是微不足道的。也就是说,它们将代表像素的极小部分。
我正在寻找之前从 32 位到 64 位转换的人的任何其他选项或有用的建议。
最佳答案
将 float
转换为 double
时,不会发生任何“数据丢失”。该转换始终是准确的。
您的解决方案 1 和 2 在语义上完全相同,尽管 (2) 在风格上更正确。
你的解决方案 3 在形式上是不等价的;它可能会在 float 和 double 之间产生额外的转换,这可能会使其效率稍低(但实际结果是相同的)。
基本上没关系,但是用tgmath
。
关于ios - 替换 `fabs` 、 `fmax` 等,用于 64 位 iOS 设备上的 CGFloat,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19506238/
我试图随机生成 CGFloat 但不知道它是如何在 swift 3 中完成的。什么是 CGFloat.random(min: CGFloat, max: CGFloat) 相当于 swift 2 的
我收到一个错误,我不知道如何修复。错误是: Sending 'CGFloat' (aka 'float') to parameter of incompatible type 'CGFloat *'
我有一个自动布局便利功能,可以将 View 堆叠在彼此之上。对于我的间距参数,我想允许: View 之间的间距为零 或单个CGFloat(所有 View 均匀分布) 或 CGFloat 数组( Vie
尝试设置 CAShapeLayer 的 zPosition 时出现错误。这是代码: self.view.layer.sublayers[l].zPosition = CGFloat(1) 出于某种原因
我有一个像 CGFloat 数组 [[[1,2],[2,3]],[[6,1],[5,6]],[[6,1],[11,6],[21,3]]] 不,我想合并子数组并在每个子数组中添加数组数据,如 [[1,2
我有这个代码: let startX = CGFloat(arc4random_uniform(maxX + (quarterX*2))) - quarterX quarterX 是一个 CGFloa
我在 XCode 6 beta 4 上使用 swift 时遇到问题,这让我发疯 我正在 IOS 8 中开发游戏并且我遵循了教程但我得到了这个:Float is not convertible to C
我正在尝试使用 CGRect.insetBy( dx : ... , dy : ...) 但是代码给了我一个根本无法解决的错误。 func scaleRect (rect: CGRect , xSca
我不太理解这个编译错误,因为我没有得到这个错误并且可以在真实设备上编译和运行,但是如果我尝试在模拟器上构建和运行我会得到这个错误。 Cannot invoke initializer for type
我有一个简单的例子,我尝试画一个圆。下面这段代码没有给我一个圆圈。 import UIKit class PlayingCardView: UIView { override func dra
我正在尝试转换使用 Facebook's pop library 的 ObjC 类 swift 。 Pop 使用了相当多的 C。 在 ObjC 中,我有一个看起来像这样的 block ...... p
我必须将我的整数包装在 CGFloat() 中才能在 Swift 2.3 中编译 如果我只执行 * 2,那么它会编译。为什么会这样?这在 Swift 3 中已修复吗? var multiplier =
我正在尝试创建一个带有CGFloat参数并返回CGFloat的块变量。 CGFloat (^debt)(CGFloat) = ^(CGFloat myFloat) { return myFloa
label.position = CGPointMake(self.size.width*0.125, self.size.height-CGFloat(0.15)*self.size.height*
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 这个问题似乎与 help center 中定义的范围内的编程无关。 . 关闭 9 年前。 Improve
如果这说明了问题,这里是原始的 Objective-C 代码。 int x = (arc4random()%(int)(self.gameView.bounds.size.width*5)) - (i
我正在尝试将 Float 值转换为 CGFloat 值,这里是我的代码: let myFloatForR = 0 let r = CGFloat(myFloatForR) le
我是 sprite kit 2d 游戏开发的新手。现有的 swift2 项目运行良好,但不幸的是更新 swift4 后流动代码出现错误。我该如何解决这个问题 class SGScene : SKSce
我的 .h 类中有以下内容: extern CGFloat tableMarginSide; extern CGFloat tableMarginTop; extern CGFloat fromIma
在我的 CGFloat 包装器中,我收到一个错误 Returning CGFloat (aka Double) from a function result type CGfloat aka doub
我是一名优秀的程序员,十分优秀!