首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iAd in UITableViewController

iAd in UITableViewController
EN

Stack Overflow用户
提问于 2014-07-25 02:22:04
回答 1查看 169关注 0票数 1

我有一个UITableViewController,我想将iAds添加到其中。我希望广告在任何时候都显示在屏幕的底部。我在这里遵循了答案:https://stackoverflow.com/a/9857798/2584268并实现了这种行为。但是,广告隐藏在开头,只有在用户滚动表时才会出现。当视图加载时,而不仅仅是用户滚动时,我如何才能让广告出现在屏幕的底部?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-07-31 23:08:31

为了在视图出现时显示广告,我在viewDidAppear上添加了横幅视图。

代码语言:javascript
复制
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

_myIAD = [[self appdelegate] myIAD];

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)
{
    //iPhone code
    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 50, 320, 50);
        }
        else
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 114, 320, 50);
        }
    }
    else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
    {
        if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 32, 480, 32);
        }
        else
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 84, 480, 32);
        }
    }
}
else
{
    //iPad code
    if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortrait || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 66, 768, 66);
        }
        else
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 130, 768, 66);
        }
    }
    else if ([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft || [UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeRight)
    {
        if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1)
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 66, 1024, 66);
        }
        else
        {
            _myIAD.frame = CGRectMake(0, _myTableView.frame.size.height - 130, 1024, 66);
        }
    }
}

[self.view addSubview:_myIAD];
}

里面有大量的代码来处理iOS6.1、iPads和iPhones,但是它确实工作得很好。我总是喜欢用statusBarOrientation来找到方向,它工作得更好。

如你所见,有一条线

代码语言:javascript
复制
_myIAD = [[self appdelegate] myIAD];

实际上,我在应用程序委托中制作了横幅,并在所有视图控制器中使用它。为了处理轮转,我在viewDidLoad中注册了通知。

代码语言:javascript
复制
- (void)viewDidLoad
{
[super viewDidLoad];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateUI:) name:UIDeviceOrientationDidChangeNotification object:nil];
}

并且基本上在viewDidAppear中updateUI方法中使用相同的代码:

我所做的另一件事是将这段代码放入代码中,以使iAd保持在底部。

代码语言:javascript
复制
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect frame = _myIAD.frame;
frame.origin.y = _myTableView.contentOffset.y + _myTableView.frame.size.height-_myIAD.frame.size.height; // Move view to the bottom on scroll
_myIAD.frame = frame;
[_myTableView bringSubviewToFront:_myIAD];
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24947068

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档