【问题标题】:Swift conversions, CGFloat to IntegerSwift 转换,CGFloat 到 Integer
【发布时间】:2014-10-10 07:44:50
【问题描述】:

如何将 @IValue CGFloat 转换为 Int?

我不断收到cannot convert @IValue CGFloat to Integer,其中包含以下内容:

@IBOutlet var userObject : UIImageView


func returnYPosition(yPosition: Integer) -> Integer {
    return userObject.center.y
}

【问题讨论】:

  • Integer 已重命名为 IntegerType。但我认为您可能试图返回 Int 而不是 IntegerType。所以把签名改成func returnYPosition(yPosition: Int)->Int等
  • 可以在这里找到一个好的解决方案:stackoverflow.com/questions/24029917/…
  • 谢谢!我终于让它工作了!是的,我试图得到一个 Int,我知道我有什么 Integer haha​​ @user1790252
  • 这帮助我终于弄清楚如何更改变量的类型!谢谢! @明尼苏达史蒂夫

标签: ios swift xcode integer cgfloat


【解决方案1】:

您需要来回传递Int 类型,然后进行强制转换:

func returnYPosition(yPosition: Int) -> Int {
    return Int(userObject.center.y)
}

【讨论】:

    猜你喜欢
    • 2016-10-22
    • 2014-09-27
    • 2018-10-12
    • 2014-07-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多