iOS 可滚动屏幕或使用自动布局固定页脚

iOS Scrollable screen OR with a pinned footer using Autolayout

UIScrollView AutoLayout With 'Footer' Pinned to Bottom of Screen不同

我想要一个包含可变高度内容和页脚的屏幕。当内容较少时,页脚应紧贴底部,与内容之间留有空隙。当内容超过屏幕时,屏幕应该是可滚动的,页脚应该出现在内容之后。

Few contents:                  Lots of contents:

+---------+                     +---------+
| Content |                     | Content |
| Content |                     | Content |
| Content |                     | Content |
|         |                     | Content |
|         |                     | Content |
| Footer  |                     | Content |
+---------+  < Screen bottom >  +---------+
                                | Content |
                                | Footer  |

我需要它 iOS7 兼容。

我对实现(滚动视图、表格视图等)没有具体要求,但我想通过自动布局(或任何更早的自动执行操作的方式)来完成这一切。

我不介意有一些代码来响应这两种不同的情况,只要它支持动态内容高度。我不热衷于监视 UI 大小变化,但是,如果可以以一种合理干净的方式完成,那就这样吧。

抱歉,我之前误解了你的问题。但我认为这应该有效。在 ypur tableView 中添加一个 UIToolbar

-(void)viewDidLayoutSubviews { [_tableView reloadData];

CGRect newFrame = _toolBar.frame;
newFrame.origin.y = _tableView.contentSize.height > CGRectGetHeight(_tableView.frame) ? _tableView.contentSize.height : CGRectGetHeight(_tableView.frame);
_toolBar.frame = newFrame;
}

我认为代码是可以自我解释的。 :)