如何在搜索栏和搜索显示控制器中使用UIScrollView?

时间:2014-05-27 04:55:42

标签: iphone ios7 xcode5.1

我想在UIScrollViewSearch 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];
    }
}

0 个答案:

没有答案