3 回答

TA貢獻(xiàn)1859條經(jīng)驗(yàn) 獲得超6個(gè)贊
對(duì)此的一個(gè)解決方案是延伸UIViewController
而不是UITableViewController
。您需要添加自己的表視圖并設(shè)置所有內(nèi)容。然后,您可以將按鈕添加到視圖控制器的視圖而不是表視圖。

TA貢獻(xiàn)1811條經(jīng)驗(yàn) 獲得超6個(gè)贊
你也可以這樣做UITableViewController(不需要普通的UIViewController,它可以嵌套你的桌子或VC)
使用SafeAreas更新iOS11 +
您想使用autolayout將視圖保持在底部
{
[self.view addSubview:self.bottomView];
[self.bottomView setTranslatesAutoresizingMaskIntoConstraints:NO];
UILayoutGuide * safe = self.view.safeAreaLayoutGuide;
[NSLayoutConstraint activateConstraints:@[[safe.trailingAnchor constraintEqualToAnchor:self.bottomView.trailingAnchor],
[safe.bottomAnchor constraintEqualToAnchor:self.bottomView.bottomAnchor],
[safe.leadingAnchor constraintEqualToAnchor:self.bottomView.leadingAnchor]]];
[self.view layoutIfNeeded];
}
并確保視圖始終位于頂部
- (void)viewDidLayoutSubviews {
[super viewDidLayoutSubviews];
[self.view bringSubviewToFront:self.bottomView];
}
以前的舊解決方案
通過(guò)滾動(dòng)表格,您需要調(diào)整“浮動(dòng)”視圖的位置,它會(huì)很好
如果您在UITableViewController中,只需
如果要將視圖浮動(dòng)在UITableView的頂部
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGRect frame = self.floatingView.frame;
frame.origin.y = scrollView.contentOffset.y;
self.floatingView.frame = frame;
[self.view bringSubviewToFront:self.floatingView];
}
如果你想浮動(dòng)UITableView底部的視圖
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
CGRect frame = self.floatingView.frame;
frame.origin.y = scrollView.contentOffset.y + self.tableView.frame.size.height - self.floatingView.frame.size.height;
self.floatingView.frame = frame;
[self.view bringSubviewToFront:self.floatingView];
}
我相信這是你問(wèn)題的真正答案
- 3 回答
- 0 關(guān)注
- 588 瀏覽
添加回答
舉報(bào)