gpt4 book ai didi

iphone - 触摸外部时隐藏 UITableViewController 中的 UIPickerView

转载 作者:行者123 更新时间:2023-12-03 21:19:20 24 4
gpt4 key购买 nike

现在我的 UITableViewController 中有 2 个不同的 UIPickerView。我仅在点击表格中的某些单元格时显示它们。我想做的是每当我触摸拾取器外部时隐藏拾取器。是否有委托(delegate)方法或类似的方法来实现此目的?我更喜欢将 Controller 保留为 UITableViewController 而不是简单的 UIViewController,因为我在其中一个单元格中有一个 textView,并且在键盘显示后滚动在 UIViewController 中有点太多了。

提前致谢。

最佳答案

可能的解决方案之一是,当点击特定单元格并处理选择器(以显示选择器)时,您可以在表格 View 上插入一个名为“MASK View”的 View 。 (框架为 self.tableview.frame - yourPicker.frame.size.height )。现在,当您点击此 View 时,您可以按如下方式处理它

-(void)showMaskView{
if (!viewMaskView) {
CGRect viewRect = CGRectMake(0, 0, self.tableView.frame.size.width, self.tableView.frame.size.height - yourPicker.frame.size.height);
viewMaskView = [[MaskView alloc] initWithFrame:viewRect];
viewMaskView.delegate = self;
}
[self.view addSubview:viewMaskView];
[self.view bringSubviewToFront:viewMaskView];
}

-(void)removeMaskView{
if (viewMaskView) {
[viewMaskView removeFromSuperview];
}
//Remove the Picker
}

在 MaskView 类中,您可以按如下方式处理触摸

-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
if(self.delegate && [self.delegate respondsToSelector:@selector(removeMaskView)])
[self.delegate removeMaskView];
}

您可以在图像中的选取器上看到彩色蒙版 View 。当点击时,它会删除选择器。 enter image description here

关于iphone - 触摸外部时隐藏 UITableViewController 中的 UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6299453/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com