我想在UIScrollView
和Search Bar
中添加Search Display Controller
,但问题是Search Bar
在点击它时会被隐藏。请给出一些建议来解决这个问题。
我正在使用以下键盘显示/隐藏通知。
- (void)registerForKeyboardNotifications {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWasShown:) name:UIKeyboardDidShowNotification object:nil];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden:) name:UIKeyboardWillHideNotification object:nil];
}
- (void)deregisterFromKeyboardNotifications {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardDidHideNotification object:nil];
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)keyBoardWasShown {
CGPoint buttonOrigin = self.txtfield2.frame.origin;
CGFloat buttonHeight = self.txtfield2.frame.size.height;
CGRect visibleRect = self.view.frame; visibleRect.size.height -= keyboardSize.height;
if (!CGRectContainsPoint(visibleRect, buttonOrigin)){
CGPoint scrollPoint = CGPointMake(0.0, buttonOrigin.y - visibleRect.size.height + buttonHeight);
[self.scrollView setContentOffset:scrollPoint animated:YES];
}
}