Objective c 从触摸中禁用某些UIView

Objective c 从触摸中禁用某些UIView,objective-c,Objective C,我有一个名为TileView的类,它扩展了UIView。在另一个视图中,我创建了9个TileView对象并在屏幕上显示它们。下面是其中一个示例 tile1 = [[TileView alloc] initWithFrame:CGRectMake(20,20, 100, 150) withImageNamed:@"tile1.png" value: 1 isTileFlipped: NO];

我有一个名为TileView的类,它扩展了UIView。在另一个视图中,我创建了9个TileView对象并在屏幕上显示它们。下面是其中一个示例

tile1 = [[TileView alloc]
             initWithFrame:CGRectMake(20,20, 100, 150)
             withImageNamed:@"tile1.png"
             value: 1
             isTileFlipped: NO];
用户可以触摸任何瓷砖。当触摸一块瓷砖时,它被“翻转”——图像被命名为纯棕色瓷砖,
isTileFlipped
被设置为“是”。现在我被卡住了:有一个确认按钮

当按下确认按钮时,它将获取所有翻转的磁贴并将它们添加到名为
acceptedTiles
的数组中。按下确认后,我需要确保无法按下或与
acceptedTiles
中的互动程序。我不知道怎样做才是最好的办法。这里是
触摸开始
,您可以了解正在发生的事情

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{

int currentTileCount = [(BoxView *)self.superview getTileCount];
int currentTileValue = [self getTileValue];
int tilecount;

if (!isFlipped) {
    [image setImage:[UIImage imageNamed:@"tileflipped.png"]];
    isFlipped = YES;
    tilecount = currentTileCount + currentTileValue;
    [(BoxView *)self.superview setTileCount:tilecount];
    [(BoxView *)self.superview addToArray:self index:currentTileValue-1];
}

else {
    [image setImage:[UIImage imageNamed:imageNamed]];
    isFlipped = NO;
    tilecount = currentTileCount - (int)currentTileValue;
    [(BoxView *)self.superview setTileCount:tilecount];
    [(BoxView *)self.superview removeFromArray: currentTileValue-1];
}
}

如果您不想对代码进行太多更改,可以先检查视图是否已添加到
acceptedTiles
,然后再在
touchsbegind:withEvent
中执行任何其他操作,以及它是否刚刚返回


但是,我想知道为什么您不在这里使用
uitappesturerecognizer
?如果您这样做了,您可以设置一个实现了
手势识别器shouldBegin:
方法的代理,在该方法中,您可以检查视图是否位于
acceptedTiles
中,而不是将其与其他点击识别逻辑混合在一起

如果您只想不与互动程序交互,那么只需:

for (UIView *tile in acceptedTiles) {
    [tile setUserInteractionEnabled:NO];
}

如果这不符合您的要求,请详细说明。这对你来说似乎很完美。

我想这会在接触开始时就开始了。没关系,这很好。我以前曾尝试过做这种事情,但实施错误。再次感谢。