简体   繁体   English

setAutoresizingMask:UIViewAutoresizingFlexibleWidth不会将iAD拉伸到全屏

[英]setAutoresizingMask:UIViewAutoresizingFlexibleWidth does not strech iAD to full landscape

I have created an app that only runs in landscape mode. 我创建了一个仅在横向模式下运行的应用程序。 I am attempting to make it so that the add will stretch across a screen in landscape. 我正在尝试使其添加到横向延伸的屏幕上。 Recent questions state that 最近的问题指出

[self.bannerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];

should give me the desired effect, but this is not the case. 应该给我想要的效果,但事实并非如此。 I create the banner programmatically. 我以编程方式创建横幅。 The code for my banner is 我的横幅的代码是

    //allocate add banner
self.bannerView = [[ADBannerView alloc]initWithAdType:ADAdTypeBanner];
[self.bannerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleTopMargin];

//_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;

/*CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;

self.bannerView.frame = bannerFrame;*/


[self.view addSubview:self.bannerView];

All the delegate methods are included later in the project. 所有委托方法都包含在项目的后面。

I managed to fix it by forcing the iAD to be the width of the view 我设法通过将iAD设置为视图的宽度来修复它

    //allocate add banner
self.bannerView = [[ADBannerView alloc]initWithAdType:ADAdTypeBanner];
[self.bannerView setAlpha:0];
[self.bannerView setDelegate:self];

//_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
[self.bannerView setAutoresizingMask:UIViewAutoresizingFlexibleWidth];




CGRect contentFrame = self.view.bounds;
CGRect bannerFrame = _bannerView.frame;
bannerFrame.size.width = contentFrame.size.width;
self.bannerView.frame = bannerFrame;
bannerFrame = _bannerView.frame;
contentFrame.size.height -= _bannerView.frame.size.height;
bannerFrame.origin.y = contentFrame.size.height;
self.bannerView.frame = bannerFrame;


[self.view addSubview:self.bannerView];

When you create the object if you set the width property to the width of the screen it will work. 创建对象时,如果将width属性设置为屏幕的宽度,它将起作用。 Example: 例:

iAds_View = [[ADBannerView alloc] initWithFrame:CGRectMake(0, 0, screen_Width, iAds_View.frame.size.height)];

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

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