ScrollView中的多个UIPickerView无法隐藏

时间:2014-07-14 19:12:15

标签: ios uiscrollview uipickerview

我有一个隐藏的多个UIPickerView在静态应用程序中正常工作。但是,当我将它添加到具有滚动视图的应用程序时,当您离开选择器时它不再隐藏。

UIPickerView:

picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,100,400,160)];
    picker.showsSelectionIndicator = TRUE;
    picker.dataSource = self;
    picker.delegate = self;
    picker.hidden = YES;
    [self.view addSubview:picker];


}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    picker.hidden = YES;
}

我需要添加任何内容,因为它现在处于滚动视图中吗?

非常感谢

1 个答案:

答案 0 :(得分:0)

通过在viewDidLoad:

之后添加这段代码解决了问题
UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc]
                                      initWithTarget:self action:@selector(tap:)];
    [self.view addGestureRecognizer: tapRec];
}

-(void)tap:(UITapGestureRecognizer *)tapRec
{
    [[self view] endEditing: YES];
    // Hide picker
    [picker resignFirstResponder];
    picker.hidden = YES;

}