首页 > 代码库 > Objective-C UIWebView添加脚视图

Objective-C UIWebView添加脚视图

- (void)addObserverForWebViewContentSize{
    [self.webView.scrollView addObserver:self forKeyPath:@"contentSize" options:0 context:nil];
}
- (void)removeObserverForWebViewContentSize{
    [self.webView.scrollView removeObserver:self forKeyPath:@"contentSize"];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
    //在这里边添加你的代码
    [self layoutCell];
}
//设置footerView的合理位置
- (void)layoutCell{
    //取消监听,因为这里会调整contentSize,避免无限递归
    [self removeObserverForWebViewContentSize];
    CGSize contentSize = self.webView.scrollView.contentSize;

    self.btnView.frame = CGRectMake(0, contentSize.height, ScreenWidth, 60);
      [self.webView.scrollView addSubview:self.btnView];
    self.webView.scrollView.contentSize = CGSizeMake(contentSize.width, contentSize.height + 60);
    //重新监听
    [self addObserverForWebViewContentSize];
}
-(AgreeBtnCell *)btnView{

    if (!_btnView) {
        _btnView = [AgreeBtnCell cell];
    }
    return _btnView;
}

 

Objective-C UIWebView添加脚视图