快速转换,CGFloat转换为整数

Mah*_*ray 3 xcode integer cgfloat ios swift

如何将@IValue CGFloat转换为Int?

我不断得到cannot convert @IValue CGFloat to Integer以下:

@IBOutlet var userObject : UIImageView


func returnYPosition(yPosition: Integer) -> Integer {
    return userObject.center.y
}
Run Code Online (Sandbox Code Playgroud)

Nat*_*ook 5

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

func returnYPosition(yPosition: Int) -> Int {
    return Int(userObject.center.y)
}
Run Code Online (Sandbox Code Playgroud)