gpt4 book ai didi

uipickerview - iOS 7.1 UITapGesture 不适用于 UIPickerView

转载 作者:行者123 更新时间:2023-12-03 07:53:22 27 4
gpt4 key购买 nike

我们正在使用 UIPickerView允许用户从选项列表中进行选择。我们正在添加 UIPickerView作为容器 UIView 的 subview 。然后我们将一个 UITapGestureRecognizer 添加到容器 UIView . UITapGestureRecognizer被用来通过删除它的 super View 来解除选择器。

在 iOS 7.0 和以前的版本中,这按预期工作。但是,在 iOS 7.1 中,此设置不再适用于 UITapGestureRecognizer无法识别点击并调用操作中指定的选择器(关闭选择器 View 和容器 View )。代码如下

   - (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.nameList=[[NSMutableArray alloc] initWithObjects:@"A",@"B",@"C", nil];
UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 320, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapInListPickerView:)];
[singleTap setNumberOfTapsRequired:1];
[singleTap setNumberOfTouchesRequired:1];
[myPickerView addGestureRecognizer:singleTap];
[self.view addSubview:myPickerView];
}

-(void)tapInListPickerView:(UIGestureRecognizer *)sender

{
NSLog(@"Taped in pikcer view");
}

如果需要任何其他信息或者是否有更优选的方法来执行此操作,请告诉我。

最佳答案

我有同样的问题,我终于有一个启示:P

就像 uiPickerView 上的同时手势识别器不起作用。

所以我使用手势委托(delegate)

<
UIGestureRecognizerDelegate>


 // add tap gesture
UITapGestureRecognizer* gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pickerViewTapGestureRecognized:)];
[picker addGestureRecognizer:gestureRecognizer];
gestureRecognizer.delegate = self;


-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{
// return
return true;
}

然后它的工作!

再见

关于uipickerview - iOS 7.1 UITapGesture 不适用于 UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22319427/

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