如何在iPhone 4S和iPhone 5的底部放置Admob横幅?

Mon*_*oor 2 iphone objective-c admob ios

在iPhone 5之前,我可以将admob横幅放在屏幕的底部(正好在标签栏上方).但由于iPhone 5的屏幕尺寸,现在一切都受到了干扰.我甚至试图通过Autolayout来做(它没有用).我如何为两种屏幕尺寸做到这一点?

这是我的代码 -

-(void) viewDidLoad {

[super viewDidLoad];

        adMob = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,
                                                                367.0 -
                                                                GAD_SIZE_320x50.height,
                                                                GAD_SIZE_320x50.width,
                                                                GAD_SIZE_320x50.height)];

        adMob.translatesAutoresizingMaskIntoConstraints=NO;

        // Specify the ad's "unit identifier." This is your AdMob Publisher ID.
        adMob.adUnitID = @"XXXXXXXX";



        // Let the runtime know which UIViewController to restore after taking
        // the user wherever the ad goes and add it to the view hierarchy.
        adMob.rootViewController = self;
        GADRequest *request = [GADRequest request];

        request.testing=YES;
        [self.view addSubview:adMob];

        // Initiate a generic request to load it with an ad.
        [adMob loadRequest:[GADRequest request]];
        [adMob release];

     // Create a view of the standard size at the bottom of the screen.
        // Available AdSize constants are explained in GADAdSize.h.


    }
Run Code Online (Sandbox Code Playgroud)

任何帮助,将不胜感激!

小智 8

如果您使用的是iOS 6,则应使用AutoLayout.将横幅添加到视图层次结构后,可以将此代码放入广告展示位置代码中:

self.googleAdBannerView.translatesAutoresizingMaskIntoConstraints = NO;
[self.view addSubview:self.googleAdBannerView];

// Constraint keeps ad at the bottom of the screen at all times.
[self.googleAdBannerView.bottomAnchor constraintEqualToAnchor:self.view.bottomAnchor].active = YES;

// Constraint keeps ad in the center of the screen at all times.
[self.googleAdBannerView.centerXAnchor constraintEqualToAnchor:self.view.centerXAnchor].active = YES;
Run Code Online (Sandbox Code Playgroud)

  • 自动布局+1.我发现你还需要self.adBanner.translatesAutoresizingMaskIntoConstraints = NO; 或者我遇到有关冲突约束的错误. (2认同)