作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我们正在使用 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/
我是一名优秀的程序员,十分优秀!