简体   繁体   English

在Swift中将类型转换错误CGPoint转换为CGFloat

[英]Conversion Type Error CGPoint to CGFloat in Swift

   var _deltaTime = NSTimeInterval()

   var _pointsPerScndSpeed = Double()

   var bgVelocity: CGPoint = CGPointMake(_pointsPerScndSpeed, 0.0)

      //Cannot convert the expression's to type 'CGFloat'

     var amToMove:CGPoint = CGPointMake(bgVelocity.x * _deltaTime, bgVelocity.y * _deltaTime)

       //Could not find an overload for '*' that accepts the supplied Arguments

The members of CGPoint have the the type CGFloat , which is a Float on the 32-bit architecture and Double on the 64-bit architecture. CGPoint的成员的类型为CGFloat ,它是32位体系结构上的Float ,而在64位体系结构上是Double Swift does not implicitly convert types. Swift不会隐式转换类型。 You can either use CGFloat consistently in your code, or add explicit casts: 您可以在代码中一致地使用CGFloat ,或添加显式强制转换:

var bgVelocity: CGPoint = CGPointMake(CGFloat(_pointsPerScndSpeed), 0.0)
var amToMove:CGPoint = CGPointMake(bgVelocity.x * CGFloat(_deltaTime), bgVelocity.y * CGFloat(_deltaTime))

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

相关问题 Swift数字和CGFloat(CGPoint,CGRect等) - Swift numerics and CGFloat (CGPoint, CGRect, etc.) 快速将自定义类型转换为CGFloat - Convert custom type to CGFloat in swift Swift 3中类型转换期间发生错误 - an error during a type conversion in Swift 3 Swift 按错误排序:无法转换“CGFloat”类型的值? 到预期的参数类型'Self' - Swift sorted by error: Cannot convert value of type 'CGFloat?' to expected argument type 'Self' swift 3中类型“ CGPoint”的值没有成员“ makeWithDictionaryRepresentation” - Value of type 'CGPoint' has no member 'makeWithDictionaryRepresentation' in swift 3 Swift编译错误:'Double'不能转换为CGFloat - Swift Compiler error: 'Double' is not convertible to CGFloat UInt8在iOS Swift中无法转换为CGFloat错误 - UInt8 is not convertible to CGFloat error in iOS Swift Swift(iOS)中的“'CGFloat'无法转换为'Double'”错误 - “'CGFloat' is not convertible to 'Double'” error in Swift (iOS) swift无法将类型(_,_)-> _的值转换为预期的参数类型'((_,CGFloat))-> _ - swift cannot convert value of type (_, _) -> _ to expected argument type '((_, CGFloat)) -> _ Swift“无法使用类型为((@lvalue CGFloat,$ T7)'的参数列表调用'-=' - Swift "Cannot invoke '-=' with argument list of type '(@lvalue CGFloat, $T7)'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM