我正在使用点按手势添加子视图:
来自UIView类(masterButton)的:
[self addSubview:self.button]; // Add gesture recognizers [self addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];
的ViewController:
masterButton * button = [[masterButton alloc] initWithFrontImage:img ]。
[self.view addSubview:button];
我删除了子视图:
UIView * button = [controller.view viewWithTag:controller.tagButton]; [button removeFromSuperview];
它触发的点击手势播放音频文件并且工作得很好但是当我删除子视图并且我点击子视图所在的相同区域时它播放音频就像子视图在那里一样。如果主视图没有响应子视图的任何手势,我该如何添加子视图?
我正在从UIview子类生成子视图,如果我尝试添加这样的手势:
[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];
它不起作用。你们谁都知道为什么?
我真的很感谢你的帮助。
答案 0 :(得分:1)
添加按钮
[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]]
[self.button removeFromSuperview];
答案 1 :(得分:0)
您正在将UITapGestureRecognizer添加到主视图
将UITapGestureRecognizer添加到self.button
而不是self
[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];
[self addSubview:self.button];
答案 2 :(得分:0)
只需将Gesture添加到masterButton就像下面那样..
[self.button addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(isTapped:)]];