【发布时间】:2014-11-03 15:31:41
【问题描述】:
所以每当我有这个:
let result = SKScrollingNode(color: UIColor.clearColor(), size:CGSizeMake(CGFloat(containerWidth), image.size.height));
我收到 image.size.height 的编译错误,告诉我“'UIImage?'尽管有,但没有名为“size”的成员
知道这意味着什么以及如何解决吗?
谢谢!
整个代码片段:
class func scrollingNode(imageNamed: String, containerWidth: CGFloat) -> SKScrollingNode {
let image = UIImage(named: imageNamed);
let result = SKScrollingNode(color: UIColor.clearColor(), size: CGSizeMake(CGFloat(containerWidth), image.size.height));
result.scrollingSpeed = 1.0;
var total:CGFloat = 0.0;
while(total < CGFloat(containerWidth) + image.size.width!) {
let child = SKSpriteNode(imageNamed: imageNamed);
child.anchorPoint = CGPointZero;
child.position = CGPointMake(total, 0);
result.addChild(child);
total+=child.size.width;
}
return result;
【问题讨论】:
-
UIImage有一个size。UIImage?没有。 -
仍然不起作用:UIImage.size.height。得到同样的错误,所以这不是问题
-
您能否解释一下这一点:“使用可选链解开图像的可选并使用 UIImage 的 frame 属性。”不太明白。
-
你能在我的代码中显示它吗?如果你愿意,你可以编辑它
标签: swift compiler-errors operand cgfloat