【发布时间】:2014-11-27 12:36:09
【问题描述】:
这是我的代码。我将两个值传递给 CGRectMake(..) 并获取错误。
let width = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).width
// return Int32 value
let height = CMVideoFormatDescriptionGetDimensions(device.activeFormat.formatDescription as CMVideoFormatDescriptionRef!).height
// return Int32 value
myLayer?.frame = CGRectMake(0, 0, width, height)
// returns error: '`Int32`' not convertible to `CGFloat`
如何将Int32 转换为CGFloat 以不返回错误?
【问题讨论】:
-
直接将
Int转换为CGFloat可能会很耗时。如果 API 可用,请考虑使用不同的方法。比如你可以从Int创建CGSize,然后再做let dividedSize =size.applying(.init(scaleX: 0.5, y: 0.5)),而不是把Int的转换成CGFloat进行除法。
标签: swift ios8.1 cgfloat int32