如何将Int32值转换为CGFloat?
发布时间:2020-12-14 05:52:28 所属栏目:百科 来源:网络整理
导读:这里我的代码, let width = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!)。width – return Int32 let height = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDe
这里我的代码,
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 = 10 let 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!).width let height = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).height myLayer?.frame = CGRectMake(0,CGFloat(width),CGFloat(height)) 请注意,swift中的数字类型之间没有隐式或显式类型转换,所以您必须使用相同的模式,也可以将Int转换为Int32或UInt等。 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |