xcode Swift 转换,CGFloat 到整数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25345624/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:24:10  来源:igfitidea点击:

Swift conversions, CGFloat to Integer

iosswiftxcodeintegercgfloat

提问by Mahmud Ahmad

How do you convert a @IValue CGFloat to an Int?

如何将@IValue CGFloat 转换为 Int?

I keep getting a cannot convert @IValue CGFloat to Integerwith the following:

我不断收到cannot convert @IValue CGFloat to Integer以下内容:

@IBOutlet var userObject : UIImageView


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

回答by Nate Cook

You need to pass Inttypes back and forth, and then just cast:

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

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