iOS工具栏出现在UITableView上吗?

时间:2014-04-11 22:51:30

标签: ios uitableview

我有一个帖子详细信息页面,显示帖子和任何评论,我试图在其底部添加一个工具栏,其中包含一个输入和一个允许他们快速添加评论的按钮。

我正在使用cocoacontrols中的DAKeyboardControl,它允许我添加工具栏我想要的方式并让它显示在屏幕上。问题是它出现在tableView的底部(有时关闭屏幕),我希望它显示在标签栏的正上方,并在用户滚动tableView时固定在那里(好像tableView放在它后面)

我已经包含了我的代码,非常感谢任何帮助。

UIToolbar *toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f,
                                                                 self.view.bounds.size.height - 40.0f,
                                                                 self.view.bounds.size.width,
                                                                 40.0f)];
toolBar.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth;
[self.view addSubview:toolBar];

UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(10.0f,
                                                                       6.0f,
                                                                       toolBar.bounds.size.width - 20.0f - 68.0f,
                                                                       30.0f)];
textField.borderStyle = UITextBorderStyleRoundedRect;
textField.autoresizingMask = UIViewAutoresizingFlexibleWidth;
[toolBar addSubview:textField];

UIButton *sendButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
sendButton.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
[sendButton setTitle:@"Send" forState:UIControlStateNormal];
sendButton.frame = CGRectMake(toolBar.bounds.size.width - 68.0f,
                              6.0f,
                              58.0f,
                              29.0f);

[toolBar addSubview:sendButton];

self.view.keyboardTriggerOffset = toolBar.bounds.size.height;

[self.view addKeyboardPanningWithFrameBasedActionHandler:^(CGRect keyboardFrameInView, BOOL opening, BOOL closing) {
    /*
     Try not to call "self" inside this block (retain cycle).
     But if you do, make sure to remove DAKeyboardControl
     when you are done with the view controller by calling:
     [self.view removeKeyboardControl];
     */

    CGRect toolBarFrame = toolBar.frame;
    toolBarFrame.origin.y = MIN(keyboardFrameInView.origin.y, self.view.bounds.size.height) - toolBarFrame.size.height;
    toolBar.frame = toolBarFrame;

    //likely to lead to a retain cycle

    CGRect tableViewFrame = self.tableView.frame;
    tableViewFrame.size.height = toolBarFrame.origin.y;
    self.tableView.frame = tableViewFrame;
} constraintBasedActionHandler:nil];

0 个答案:

没有答案