if ([self respondsToSelector:@selector(automaticallyAdjustsScrollViewInsets)]) {
self.automaticallyAdjustsScrollViewInsets = NO; }
- (UITableView *)tableView
{
if (!_tableView) {
_tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, ScreenHeight)];
_tableView.delegate = self;
_tableView.dataSource = self;
_tableView.backgroundColor = [UIColor whiteColor];
_tableView.contentInset = UIEdgeInsetsMake(64, 0, 0, 0); _tableView.scrollIndicatorInsets = UIEdgeInsetsMake(64, 0, 0, 0); _tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLine; } return _tableView; }
这里利用了edgeInset
内嵌边距,tableView的frame依旧是全屏尺寸的,只是设置了下contentInset
使得其内容视图的尺寸改变了,
scrollIndicatorInsets
是右侧的滑动指示器,要跟着一起才自然。如果当前页还有tabBar的话,只需要设置UIEdgeInsetsMake
的bottom
值就行。
这样,上图一的毛玻璃穿透效果就自然的释放了出来。
初始化webView黑条出现在视图底部,一般高度为64,也就是contentInset
的top
值,上图的因为设置关系要大很多。
初始化时设置opaque=NO
,也就是使得view透明,但是在加载之后,要设置opaque=YES
,也就是默认不透明,这样,黑条是彻底不可见的。
在实现一些滑动视图的动态变化的处理中,例如稍后提到的动态缩放,一般会用代理检测contentOffset.y
值,但是因为设置了contentInset.top
,此时contentOffset.y
值也就发生了变化:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y + self.tableView.contentInset.top;
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGFloat offsetY = scrollView.contentOffset.y + _tableView.contentInset.top;