Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 如何更正此程序的错误_Ios - Fatal编程技术网

Ios 如何更正此程序的错误

Ios 如何更正此程序的错误,ios,Ios,我有一个代码,但在这个代码中有一个错误,我不知道为什么我有这个错误。 我之所以写这个代码,是因为我希望我的球至少击中屏幕的边缘。 您可以看到我的代码: CGPoint ballCenter = ball.center; CGRect ballRect = CGRectMake(50, 73, 50, 50); // an arbitrary location for the ball, you would normally use the frame property of the ball h

我有一个代码,但在这个代码中有一个错误,我不知道为什么我有这个错误。 我之所以写这个代码,是因为我希望我的球至少击中屏幕的边缘。 您可以看到我的代码:

CGPoint ballCenter = ball.center;
CGRect ballRect = CGRectMake(50, 73, 50, 50); // an arbitrary location for the ball, you would normally use the frame property of the ball here
CGRect s = [UIScreen mainScreen].bounds;
CGRect adjustedScreenRect = CGRectMake(s.x-50   // take the ball's (width or height) and divide it by two to get the distance to the center. Then multiply it by two and subtract from the appropriate dimension(x offset (width), y offset (height), width (width), height (height)). 
BOOL isOnScreen = CGRectContainsPoint(adjutedScreenRect, ballCenter);
// do whatever with the BOOL from the above line...
我在这行有一个错误:

CGRect adjustedScreenRect = CGRectMake(s.x-50   // take the ball's (width or height) and divide it by two to get the distance to the center. Then multiply it by two and subtract from the appropriate dimension(x offset (width), y offset (height), width (width), height (height)). 
BOOL isOnScreen = CGRectContainsPoint(adjutedScreenRect, ballCenter);
错误是“struct CGRect中没有名为“x”的成员”

谢谢你的帮助

答案是
CGRect adjustedScreenRect=CGRectMake(s.origin.x-50
BOOL isOnScreen=CGRectContainsPoint(adjutedScreenRect,ballCenter);

但我有一个错误(预期)在布尔


你能帮我一下吗?我想你指的是
s.origin.x
,而不是
s.x
。由于CGRect是CGPoint和CGSize的结构,因此如果不指定要首先访问结构的哪一部分,则无法直接访问CGRect的x值

编辑:

实际上,您从未关闭过圆括号,也没有满足CGRect的所有4个参数。试试这个:

CGRectMake(s.origin.x-50, s.origin.y, width,height);

我想你的意思是
s.origin.x
,而不是
s.x
。由于CGRect是CGPoint和CGSize的结构,因此如果不指定要首先访问结构的哪一部分,则无法直接访问CGRect的x值

编辑:

实际上,您从未关闭过圆括号,也没有满足CGRect的所有4个参数。试试这个:

CGRectMake(s.origin.x-50, s.origin.y, width,height);

是的,正是我要说的。用令人不快的代码行编辑你的帖子,我会看看我能做什么。科达菲,我用你的回答编辑了我的帖子你好,我在“宽度”使用未声明的标识符“宽度”时出错。你能帮我吗,如果我让你精神错乱了,我很抱歉。用你想要的任何数字替换宽度和高度。是的,这正是我要说的。用令人不快的代码行编辑你的帖子,我会看看我能做什么。科达菲,我用你的回答编辑了我的帖子你好,我在“宽度”使用未声明的标识符“宽度”时出错。你能帮我吗,如果我让你精神错乱了,我很抱歉。用你想要的任何数字替换宽度和高度。