在下面的代码中,由于用户 touchUpInside 在一个简单的信息按钮上,我弹出了一个 ImageView。视图上还有其他按钮。
为了消除信息,我在控制器视图中添加了一个 UITapGestureRecognizer,并在检测到点击时隐藏视图。
如果我不删除 tapGestureRecognizer,则每次都会调用该操作。
即使我确实删除了手势操作,一旦添加了此手势识别器,按钮也不会收到 touchUpInside 事件。为什么?
我的 MainViewController 中的代码
- (void) dismissInfo: (UITapGestureRecognizer *)gesture {
[kInfoView setHidden: YES];
[gesture removeTarget: self action: NULL];
}
- (IBAction) displayInfo {
CGRect startFrame = CGRectMake(725, 25, 0, 0), origFrame;
CGFloat yCenter = [kInfoView frame].size.height/2 + 200;
CGPoint startCenter = CGPointMake(724, 25), displayCenter = CGPointMake(384, yCenter);
UITapGestureRecognizer *g = [[UITapGestureRecognizer alloc] initWithTarget: self
action: @selector(dismissInfo:)];
[self.view addGestureRecognizer: g];
origFrame = [kInfoView frame];
[kInfoView setCenter: startCenter];
[kInfoView setHidden: NO];
[kInfoView setFrame: startFrame];
[UIView beginAnimations: @"info" context: nil];
[UIView setAnimationDuration: .5];
[UIView setAnimationDelegate: self];
[kInfoView setFrame: origFrame];
[kInfoView setCenter: displayCenter];
[UIView commitAnimations];
}