简体   繁体   English

确定何时在屏幕上显示UITableView TableHeaderView或TableFooterView

[英]Determine when UITableView TableHeaderView or TableFooterView is displayed on screen

I'm trying to determine when a tableHeaderView or tableFooterView is actually rendered on the screen. 我试图确定何时在屏幕上实际呈现tableHeaderView或tableFooterView。 The problem I'm facing is I can only have 1 ad view rendered at a time. 我面临的问题是我一次只能呈现1个广告视图。 If I put it in the header and then the footer, it removes it from the header. 如果我将其放在页眉中,然后再放在页脚中,则会将其从页眉中删除。 So what I want to do is, when the footer shows up on the screen, move the ad view into the footer and when the header shows up on the screen, move the ad view into the header. 所以我想做的是,当页脚显示在屏幕上时,将广告视图移至页脚中,而当页眉显示在屏幕上时,将广告视图移至页眉中。

Right now I'm loading 2 separate ads and dropping them in each, but we want the same ad on each and the ad server recommends only loading a single ad and moving it around to where it needs to be displayed. 目前,我正在加载2个单独的广告,然后将它们放到每个广告中,但是我们希望每个广告都放同一个广告,并且广告服务器建议仅加载一个广告并将其移动到需要展示的位置。

You can use the scrollview delegate to calculate manually when each view is off the screen 当每个视图不在屏幕上时,您可以使用scrollview委托手动进行计算

This post has what you need I believe 我相信这篇文章有您需要的

https://stackoverflow.com/a/27868948/4875095 https://stackoverflow.com/a/27868948/4875095

- (void)scrollViewDidScroll:(UIScrollView *)scrollView {

static CGFloat lastY = 0;

CGFloat currentY = scrollView.contentOffset.y;
CGFloat headerHeight = self.headerView.frame.size.height;

if ((lastY <= headerHeight) && (currentY > headerHeight)) {
    NSLog(@" ******* Header view just disappeared");
}

if ((lastY > headerHeight) && (currentY <= headerHeight)) {
    NSLog(@" ******* Header view just appeared");
}

lastY = currentY;

} }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM