这是我的代码。我将两个值传递给 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 进行除法。 - Oleksii Nezhyborets