UISearchBar hinzufügen über Tastatur
ich eine Suchleiste über der Tastatur angezeigt werden soll. Immer wenn die Tastatur erscheint, sollte auch die Suchleiste erscheinen. Wie macht man das?
UISearchBar hinzufügen über Tastatur
ich eine Suchleiste über der Tastatur angezeigt werden soll. Immer wenn die Tastatur erscheint, sollte auch die Suchleiste erscheinen. Wie macht man das?
ein Objekt von UISearch bar Erstellen und einen Beobachter für Tastatur in textFieldDidBeginEditing/textViewDidBeginEditing hinzufügen
- (void)textViewDidBeginEditing:(UITextView *)textView
{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWasShown:)
name:UIKeyboardDidShowNotification
object:nil];
}
- (void)keyboardWasShown:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
int height = MIN(keyboardSize.height,keyboardSize.width);
int width = MAX(keyboardSize.height,keyboardSize.width);
//set frame for searchbar
searchBar.frame = CGRectMake(0, self.view.frame.size.height - height, width, 50);
}
kein Glück ?? ..... – Developer
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillShow:) name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillShowNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyboardWillShow:(NSNotification *)notification
{
CGSize keyboardSize = [[[notification userInfo] objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = -keyboardSize.height;
self.view.frame = f;
}];
}
-(void)keyboardWillHide:(NSNotification *)notification
{
[UIView animateWithDuration:0.3 animations:^{
CGRect f = self.view.frame;
f.origin.y = 0.0f;
self.view.frame = f;
}];
}
Sie können einfach textField.inputAccessoryView = Ihre Suchleiste
textField.inputAccessoryView = mySearchBar;
Willkommen bei Stack Overflow! Während dieser Codeabschnitt die Frage beantworten kann, ist es besser, eine Beschreibung des Problems einzubeziehen, und wie Ihr Code das gegebene Problem angehen wird. Für die Zukunft gibt es hier einige Informationen zu Stack Overflow (http://stackoverflow.com/help/how-to-answer). – dirtydanee
kann u zeigen verwenden Ihr versuchte Code –
Ich habe Suchleiste programmatisch erstellt und denke daran, es als Eingabeansicht der Tastatur hinzuzufügen ... Aber keine Idee, in Code zu implementieren ... –