【发布时间】:2012-12-12 02:17:50
【问题描述】:
我有许多弹出视图保存为视图控制器的属性。它们仅在呈现时添加到视图中,并在隐藏时从视图中移除。一切正常,但我更改了代码以简化事情,但它不再工作了。
以下是我如何创建和添加手势识别器的示例:
UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hidePopUpView:)];
[self.totalPowerPopUpView addGestureRecognizer:tapGestureRecognizer];
[self.co2PopUpView addGestureRecognizer:tapGestureRecognizer];
视图由按下 UIButton 触发的选择器呈现(通常在 if 语句中设置自定义视图属性的其他代码,但为简单起见,我将其删除):
- (void)showPopUpView:(UIButton*)sender
{
CGRect endFrame = CGRectMake(10, 10, 300, 400);
UIView *popUpView;
if (sender == self.totalPowerInfoButton)
{
[self.view addSubview:self.totalPowerPopUpView];
popUpView = self.totalPowerPopUpView;
}
if (sender == self.co2LevelInfoButton)
{
[self.view addSubview:self.co2PopUpView];
popUpView = self.co2PopUpView;
}
[UIView animateWithDuration:0.5
animations:^ {
popUpView.alpha = 1.0;
popUpView.frame = endFrame;
}];
}
popUpView 存在,但是当我点击它们时,手势识别器选择器不会被调用。为什么不呢?
【问题讨论】:
标签: ios uiview uigesturerecognizer