How can use CGFloat in Swift?

房东的猫 提交于 2019-12-04 22:42:30

Use CGFloat(number) instead of Float(number)

pipeDown.position = CGPointMake(0.0, CGFloat(posinonY))
Seivan

Since CGFloat is not a Double on 32bit, it becomes hard to use CGGeometry and frameworks like CoreGraphics or SpriteKit. This library makes it a little easier and hopefully Apple takes care of it soon.

I wrote this to help out https://github.com/seivan/ScalarArithmetic

But if you want to just make it work without dependencies use var myFloat:CGFloat explicitly, and make sure to cast any Double (numbers that are type inferred) to CGFloat 2.0 is inferred to be a Double and won't play along with the CG-Structs on 32bit.

As in Swift 4

use

CGPoint(x: 12.0, y: 100.0)
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!