
let wIDth = CMVIDeoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVIDeoFormatDescriptionRef!)。wIDth – return Int32
let height = CMVIDeoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVIDeoFormatDescriptionRef!)。height – return Int32
myLayer?.frame = CGRectMake(0,0,wIDth,height)
错误是’Int32’不能转换为CGfloat,如何将Int32转换为CGfloat?
要在数值数据类型之间进行转换,将创建一个新的目标类型实例,将源值作为参数传递。所以要将Int32转换为CGfloat:let int: Int32 = 10let cgfloat = CGfloat(int)
在你的情况下,你可以做:
let wIDth = CGfloat(CMVIDeoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVIDeoFormatDescriptionRef!).wIDth)let height = CGfloat(CMVIDeoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVIDeoFormatDescriptionRef!).height)myLayer?.frame = CGRectMake(0,wIDth,height)
要么:
let wIDth = CMVIDeoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVIDeoFormatDescriptionRef!).wIDthlet height = CMVIDeoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVIDeoFormatDescriptionRef!).heightmyLayer?.frame = CGRectMake(0,CGfloat(wIDth),CGfloat(height))
请注意,swift中的数字类型之间没有隐式或显式类型转换,所以您必须使用相同的模式,也可以将Int转换为Int32或UInt等。
总结以上是内存溢出为你收集整理的如何将Int32值转换为CGFloat?全部内容,希望文章能够帮你解决如何将Int32值转换为CGFloat?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)