简体   繁体   English

“'CGFloat'无法转换为'UInt8'”-CGFloat包装问题

[英]“'CGFloat' is not convertible to 'UInt8'” - CGFloat wrapping issue

label.position = CGPointMake(self.size.width*0.125, self.size.height-CGFloat(0.15)*self.size.height*_activeEnemiesArray.count)

I get an error pointing to self.size.width that says 我收到一个指向self.size.width的错误, self.size.width

'CGFloat' is not convertible to 'Double'. “ CGFloat”不可转换为“ Double”。

This makes sense, since a CGFloat value and a Double value cannot be multiplied, but then when I convert the 0.125 to CGFloat : 这是有道理的,因为CGFloat值和Double值不能相乘,但是当我将0.125转换为CGFloat

label.position = CGPointMake(self.size.width*CGFloat(0.125), self.size.height-0.15*self.size.height*_activeEnemiesArray.count)

I get an error pointing to self.size.width that says 我收到一个指向self.size.width的错误, self.size.width

'CGFloat' is not convertible to 'UInt8' “ CGFloat”不可转换为“ UInt8”

This does not make any sense. 这没有任何意义。 Has anyone else been experiencing this and what could be the cause? 是否有其他人正在经历这种情况,可能是什么原因?

你试一试

self.frame.size.width 

Xcode is leading you astray -- literals shouldn't really ever cause problems, as they'll get converted into Double or CGFloat as needed once everything else is the same type. Xcode会让您误入歧途-文字永远不会真正引起问题,因为一旦其他所有内容都相同,它们就会根据需要转换为DoubleCGFloat Instead, what's going on is that you have an Int at the very end of your line: 取而代之的是,您在行的最后有一个Int

... * self.size.height * _activeEnemiesArray.count)

That count property needs to be converted to CGFloat so it can be used with the rest: count属性需要转换为CGFloat以便可以与其余属性一起使用:

... * self.size.height * CGFloat(_activeEnemiesArray.count))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM