iphone - if 语句的问题 ||

标签 iphone objective-c c if-statement

我正在研究一个新项目,实际上我正在使用简单的坐标:

if (locationOnJoystick.x > joystickArea.frame.size || locationOnJoystick.y > joystickArea.frame.size) {

但是在运行代码时出现错误:

error: invalid operands to binary > (have 'CGFloat' and 'CGSize')

谁能看到解决方案?!

真诚的, 特立独行3。

最佳答案

locationOnJoystick.x 是一个 CGFloat,而 joystickArea.frame.size 是一个 CGSize。它们是不同的类型,您无法比较它们。

我猜你应该比较 locationOnJoystick.x 和你的 joystickArea.frame.size 的宽度(y 和高度也一样):

if (locationOnJoystick.x > joystickArea.frame.size.width || locationOnJoystick.y > joystickArea.frame.size.height) {

关于iphone - if 语句的问题 ||,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4984809/

相关文章:

iphone - 设置特定表格单元格的 ImageView

ios - 谷歌分析跟踪没有遗产

iphone - "__workq_kernreturn"在 iOS 崩溃日志中或当您暂停应用程序执行时表示什么?

c - C中打印数组内容时出错

ios - 像 iOS 相机应用程序一样显示屏幕闪光

iphone - 对于iOS应用程序,如何使用Instruments的Memory Monitor绘制应用程序的内存使用情况?

iphone - 如何从地址簿 ios 以编程方式编辑电话号码值

ios - 在 UITableView 中实现 imageView 滑动,具有水平滚动和页面指示器

将 time_t 转换为 timeval

c - 在 Linux C 中播放音频文件的库