二元运算符+不能应用于CGfloat类型的操作数 [英] Binary Operator + Cannot be Applied to Operands of Type CGfloat int

查看:228
本文介绍了二元运算符+不能应用于CGfloat类型的操作数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了与之前不同代码行相同的问题;但是这一次,我无法用上次的方法修复它:

I am having the same problem as earlier with a different line of code; but this time, I wasn't able to fix it with the same approach as last time:

 var Y : Int = 0
 var X : Int = 0
 @IBOutlet var ball : UIImageView!
 ball.center = CGPointMake(ball.center.x + X, ball.center.y + Y) 

这是我得到的错误:


二元运算符+不能应用于CGfloat int类型的操作数

binary operator + cannot be applied to operands of type CGfloat int


推荐答案

请将它们声明为以下内容:

Declare them, instead, as the following:

let X : CGFloat = 0.0
let Y : CGFloat = 0.0

回复你的评论:

该错误与他们被声明为 var
您可以将它们声明为 var ,如果您坚持将它们声明为 Int ,您仍然会需要执行以下操作:

The error has nothing to do with them being declared as var or let. You could declare them as var and if you so insist on declaring them as Int, you would still need to do the following:

var X : Int = 0
var Y : Int = 0
ball.center = CGPointMake(view.center.x + CGFloat(X), view.center.y + CGFloat(Y))

这篇关于二元运算符+不能应用于CGfloat类型的操作数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆