Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在iPhone 4S和iPhone 5的底部都放置Admob横幅?_Iphone_Objective C_Ios_Admob - Fatal编程技术网

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

如何在iPhone 4S和iPhone 5的底部都放置Admob横幅?,iphone,objective-c,ios,admob,Iphone,Objective C,Ios,Admob,在iPhone5之前,我可以将admob横幅放在屏幕底部(就在选项卡栏上方)。但由于iPhone5的屏幕尺寸,现在一切都被打乱了。我甚至试着通过自动布局来完成它(它不起作用)。对于两种屏幕尺寸,我如何做到这一点 这是我的密码- -(void) viewDidLoad { [super viewDidLoad]; adMob = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,

在iPhone5之前,我可以将admob横幅放在屏幕底部(就在选项卡栏上方)。但由于iPhone5的屏幕尺寸,现在一切都被打乱了。我甚至试着通过自动布局来完成它(它不起作用)。对于两种屏幕尺寸,我如何做到这一点

这是我的密码-

-(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.


    }

任何帮助都将不胜感激

根据他们使用的屏幕更改
y
位置。

您必须使用视图的自动布局属性,没有其他解决方法,因为在任何设备中,视图高度保持不变,即现在的499.0。

如果您使用的是iOS 6,您应该只使用自动布局。将横幅添加到视图层次结构后,可以将此代码放入广告放置代码中:

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;

如果我改变Y位置,iPhone4屏幕上的布局将会恶化,这是一个问题。。。。我的意思是,使用对象帧的
x
y
移动对象帧。我想,你可以根据手机制作两个不同的笔尖,然后加载一个不同的笔尖。我用的是故事板。两个不同设备的两个不同笔尖对我来说没有意义。我同意。这就是为什么您应该检查他们正在使用的屏幕,并相应地设置
y
。您能否进一步了解如何将其用于admob banner?我早些时候启用了它,但视图受到干扰。如何禁用它以更改按钮布局?+1表示自动布局。我发现您还需要self.adBanner.translatesAutoresizingMaskIntoConstraints=NO;或者我在冲突约束方面出错。