我的视图控制器中有3个视图由UISegmentControl
控制,所以一旦点击每个视图,它就会在每个视图之间切换。现在请记住,它们都是堆叠的,最初是隐藏的2,并且它几乎可以切换显示/隐藏其他的。
我正在尝试设置它,以便在3个视图中的任何一个视图中点击一个区域后,它会打开另一个视图控制器。我如何在视图控制器中为所有3个视图执行此操作?我的观点包含一堆UIImages
来模仿表格列表(它是一个原型应用程序)。每个视图都没有占据整个屏幕,因为我在顶部有一个标题栏,搜索栏和底部的tabcontroller。
答案 0 :(得分:1)
如果您有对图像的引用(UIImageView组件),您应该为所有这些组件添加UITapGestureRecognizer以检测水龙头。
例如在viewDidLoad:
中UITapGestureRecognizer *img1TapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayViewController1:);
[imageView1 addGestureRecognizer:img1TapGestureRecognizer];
UITapGestureRecognizer *img2TapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayViewController2:);
[imageView2 addGestureRecognizer:img2TapGestureRecognizer];
UITapGestureRecognizer *img3TapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(displayViewController3:);
[imageView3 addGestureRecognizer:img3TapGestureRecognizer];
然后使用以下方法显示视图控制器:
- (void)displayViewController1:(UITapGestureRecognizer *)recog {}
- (void)displayViewController2:(UITapGestureRecognizer *)recog {}
- (void)displayViewController3:(UITapGestureRecognizer *)recog {}
答案 1 :(得分:0)
试试这个
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
if ([touch view] == yourDesiredImage) {
// Do something here
}
}