【发布时间】:2013-12-13 16:34:44
【问题描述】:
我正在用 Xcode 为 iPhone 创建一个井字游戏。
一切正常,我只想在 9 个方块被触摸后禁用触摸事件,例如所以用户不能点击同一个方块将值从 X 更改为 0。
我试过 touch1.userInteractionEnabled = NO;(touch1 是正方形 UIImageView 我想禁用)但没有乐趣。
有什么想法吗?
【问题讨论】:
-
使用 UI 按钮?试试
[touch1 setEnabled:NO] -
为了回答这个问题,我们需要知道您是如何处理触摸事件的。你在用什么? (例如 UIButtons?手势识别器?)
-
@Mattia 再次阅读问题,我认为他正在使用 UIImageView,但他需要显示显示他如何处理触摸的代码。
-
你的手势识别器是在imageView还是imageView的superView上?禁用 imageView 上的用户交互仅适用于其触摸处理程序。如果您在超级视图上使用单个手势并进行数学运算以找到被触摸的视图,则需要在那里管理禁用的触摸。
-
//游戏的触摸事件 -(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ UITouch *touch = [[event allTouches]anyObject]; //检查哪个方块被触摸 if(CGRectContainsPoint([_touch1 frame], [touch locationInView:self.view])){ if(token == 1){_touch1.image = one;} if(token == 2 ){_touch1.image = 零;} } }
标签: ios cocoa-touch uiimageview tic-tac-toe touch-event