Ios 如何在轻敲它们时将视图显示在前面?网间网操作系统

Ios 如何在轻敲它们时将视图显示在前面?网间网操作系统,ios,iphone,xcode,view,gesture-recognition,Ios,Iphone,Xcode,View,Gesture Recognition,每次按下按钮时,我都会创建一个图像视图的实例。创建的最后一个实例被带到前面。如何通过点击将不同的实例放到前面 - (void) hatsPressed { NSLog(@"HAT PRESSED"); hat2Image = [[UIImageView alloc] initWithFrame:CGRectMake(120, 50, 100, 100)]; hat2Image.image = [UIImage imageNamed:@"hat2"]; [self.view addSubview:

每次按下按钮时,我都会创建一个图像视图的实例。创建的最后一个实例被带到前面。如何通过点击将不同的实例放到前面

- (void) hatsPressed {
NSLog(@"HAT PRESSED");
hat2Image = [[UIImageView alloc] initWithFrame:CGRectMake(120, 50, 100, 100)];
hat2Image.image = [UIImage imageNamed:@"hat2"];
[self.view addSubview:hat2Image];
[self.view bringSubviewToFront:hat2Image];
hat2Image.userInteractionEnabled = YES;

UITapGestureRecognizer * recognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTap:)];
    recognizer.delegate = self;
[hat2Image addGestureRecognizer:recognizer];
[hat2Image addGestureRecognizer:_hat2Pan];
[hat2Image addGestureRecognizer:_hat2Pinch];
[hat2Image addGestureRecognizer:_hat2Rotate];

}
我会这么做的。。。 向实例化的每个图像视图添加手势识别器。 该手势的处理程序需要在添加图像视图的超级视图或控制器中调用委托方法

在控制器或视图中调用该代理时,只需调用

[self.view bringSubviewToFront:myTappedView];
*我会回收图像视图。。。为每个水龙头创建一个不是很好的方法

如果你需要更多的细节,请告诉我