2014-07-14 56 views
0

我有一個隱藏的多個UIPickerView在靜態應用程序中正常工作。但是,當我將其添加到具有滾動視圖的應用程序時,它不再隱藏,當你從選擇器中移開時。ScrollView中的多個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; 
} 

請問有什麼需要補充,因爲它現在處於滾動視圖?

非常感謝

回答

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; 

}