我通过屏幕上设置的 UITapGestureRecognizer 获得了 x 和 y,在获得位置后我找到了触摸的对象,所以我设置了条件,但不起作用。也许我在 Objective-C 中输入了错误的条件? Xcode 没有给出任何错误,但该函数不起作用。
-(void)tappedMapOniPad:(int)x andy:(int)y{
NSLog(@"the x is: %d", x);
//the x is: 302
NSLog(@"the y is: %d", y);
//the y is: 37
if((121<x<=181) && (8<y<=51)){ //the error is here
self.stand = 431;
}else if ((181<x<=257) && (8<y<=51)){
self.stand=430;
}else if ((257<x<=330) && (8<y<=51)){
self.stand = 429;
}
NSLog(@"The stand is %d", self.stand);
//The stand is 431
}
我该怎么办?
最佳答案
121<x<=181
让我们假设 x := 10 121<10<=181
-> false<=181
-> 0<=181
-> 真
你必须一步一步来。
((121 < x) && (x <=181))
让我们假设 x := 10 ((121 < 10) && (10 <=181))
-> false && true
-> false
关于ios - Objective C 中的逻辑运算符和错误结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14254665/