UIView触摸位置坐标
UIView 及其相应的超级视图中使用的坐标是什么?我有这段代码,我想检测用户可以触摸的“走廊”...类似于此图像:alt text http://img17.imageshack.us/img17/4416/bildschirmfoto20100721u.png
这是我的代码:
CGPoint touch = [recognizer locationInView:[shuttle superview]];
CGPoint centre = shuttle.center;
int outerRadius = shuttle.bounds.size.width/2;
int innerRadius = (shuttle.bounds.size.width/2) - 30;
if ((touch.x < outerRadius && touch.y <outerRadius)){
NSLog(@"in outer");
if(touch.x > innerRadius && touch.y > innerRadius) {
NSLog(@"in corridor");
}
}
半径约为 500 和 600,touch x 和 y 分别是 100 和 200...
因此,“走廊中”的 NSLog 永远不会被调用。
谢谢
What are the coordinates used in UIViews and their corresponding superviews? I have this code which i would like to detect a 'corridor' where the user can touch... similar to this image:alt text http://img17.imageshack.us/img17/4416/bildschirmfoto20100721u.png
This is the code i have:
CGPoint touch = [recognizer locationInView:[shuttle superview]];
CGPoint centre = shuttle.center;
int outerRadius = shuttle.bounds.size.width/2;
int innerRadius = (shuttle.bounds.size.width/2) - 30;
if ((touch.x < outerRadius && touch.y <outerRadius)){
NSLog(@"in outer");
if(touch.x > innerRadius && touch.y > innerRadius) {
NSLog(@"in corridor");
}
}
The radii are approximately 500 and 600, and the touch
x and y are 100 and 200...
Thus, the NSLog "in corridor" never gets called.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的条件不对。根据它,走廊是一个正方形,其中心位于 (0, 0),而不是
shuttle.center
。尝试一下。
即使走廊确实预计为正方形,您也应该使用 fabs(dx)、fabs(dy) 进行检查,而不是使用 touch.x、touch.y 进行检查。
Your condition is wrong. The corridor according to it is a square, with its center at (0, 0) instead of
shuttle.center
. Tryinstead.
Even if the corridor is indeed expected to be a square, you should check with
fabs(dx), fabs(dy)
nottouch.x, touch.y
.