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;
}
相關文章
相關標籤/搜索