1

我有一个带有搜索栏和搜索结果显示控制器的 UITableView:

[self.searchDisplayController.searchResultsTableView addSubview:searchIndicator];
searchIndicator.center = CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height / 2.0);

上面的代码将指示器放置在屏幕的中心。但是我想将指示器放在框架的中心,不包括键盘。我怎样才能做到这一点?

指标定义如下:

@property (retain, nonatomic) IBOutlet UIActivityIndicatorView *searchIndicator;

在此处输入图像描述

4

3 回答 3

1

@SaurabhPrajapati在他的评论中有正确的想法。您需要订阅其中一个键盘 willShow/didShow 通知(UIKeyboardDidShowNotification或 ),当您收到键盘通知时,从(在 Xcode 帮助系统中搜索该字符串以获取更多信息)UIKeyboardWillShowNotification收集有关键盘高度的信息。)保存Keyboard Notification User Info Keys将键盘高度设置为实例变量,然后当您准备好显示活动指示器时,使用键盘高度调整指示器的位置,如 Saurabh 的评论中所述。

于 2015-09-10T12:40:21.843 回答
0

您可以在UIActivityIndicatorView键盘通知的顶部和内部添加一个约束。当键盘将显示时,将其缩小键盘高度,如果键盘将被隐藏,则将键盘高度再次添加到顶部约束。

于 2015-09-10T13:13:24.793 回答
0

在 viewDidLoad 中添加这个

//KeyBoard Helpers
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyBoardWillShow:) name:UIKeyboardWillShowNotification object:nil];

然后实现这个方法

-(void)keyBoardWillShow:(NSNotification*)notification
{
    NSDictionary *userInfo = [notification userInfo];
    CGRect keyboardFrame = [[userInfo objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue];
    CGFloat keyBoardHeight = keyboardFrame.size.height;
    searchIndicator.center = CGPointMake(self.view.frame.size.width / 2.0, self.view.frame.size.height - keyBoardHeight/ 2.0);
}
于 2015-09-10T12:47:44.423 回答