2

I am trying to add UIScrollView in Search Bar and Search Display Controller but the problem is that Search Bar gets hidden when I click on it. Please give some suggestion to resolve this.

I am using the following keyboard show/hide notifications.

- (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];
    }
}
Ramaraj T
  • 5,184
  • 4
  • 35
  • 68
Sushil Sharma
  • 945
  • 1
  • 7
  • 9

0 Answers0