- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
if(touch.view==testScroll)
{
if(UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad)
{
ViewForValuePicker.hidden=true;//view to which pickerview is added and this s view is added to scrollview
pickerView.hidden=YES;
}
return YES;
}
else
return NO;
}
点击屏幕上的任意位置时,如果点击选择器视图,我该怎么做才能删除选择器视图
答案 0 :(得分:0)
尝试这样可能对你有帮助,
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
NSLog(@"touches began");
UITouch *touch = [touches anyObject];
if([touch view] isKindOfClass:[UIScrollView class]){
//do whatever you want to do here
}
}
答案 1 :(得分:0)
你可以做的是为pickerview创建第二个手势识别器,它会吞下不应该发送到scrollview的那些水龙头。
请参阅图示一个完整的测试项目来实现这一目标。您可以看到,点击pickerview被路由到 gestureswallover 方法,并且pickerview的外部所有点击都被路由到 gesturehelper 方法,因此您可以在这些方法中实现您的逻辑。
在ViewController.h中,这些是手势识别器的动作方法:- (IBAction) gesturehelper: (UITapGestureRecognizer*) sender;
- (IBAction) gestureswallover: (UITapGestureRecognizer*) sender;
在我的ViewController.m中我有这个(特定逻辑应该包含在动作方法中):
- (IBAction) gesturehelper: (UITapGestureRecognizer*) sender {
NSLog(@"gesturehelper tap, %@", sender.view);
}
- (IBAction) gestureswallover: (UITapGestureRecognizer*) sender {
NSLog(@"gestureswallover tap, %@", sender.view);
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return 5;
}