Incorrect layout after rotation if banner ads are included outside viewDidLoad

I'm having problems with iOS 8. My application needs to get information from a web server to determine if it should be advertised or not. This may take some time, so the code in viewDidLoaddoes not wait for it and instead calls it setCanDisplayBannerAds:NO. Then, when the information comes in, setCanDisplayBannerAds:YESit is called out viewDidLoad.

I have determined what I need to call setCanDisplayBannerAds:NOinternally viewDidLoad, otherwise it setCanDisplayBannerAds:YESincorrectly calls declarations and throws a lot of internal exceptions.

The problem is that after the ads are included outside viewDidLoad, the layout gets confused. I have illustrated the two images below. Upper - “before”, lower “after”, as well as after “Ad impressions”.

Pay attention to the "earlier" image, which displays ads and only the label are displayed in the corresponding corners after the rotation. In the after image, the landscape orientation is no longer correct. It supports portrait restrictions using Just Label and disabling banner ads.

I submitted an Apple bug report and provided a sample project available on DropBox as ID19658866.zip . Feel free to download it and try it.

If someone can give some idea and, possibly, a solution in which I do not need to change the logical sequence, that is, show ads until after completion viewDidLoad, this would be highly appreciated.

before * Show Ads * is tappedafter * Show Ads * is tapped

+4
source share
4 answers

Put these two lines in viewdidLoad:

[self setCanDisplayBannerAds:YES];
[self setCanDisplayBannerAds:NO];

The first call correctly sets the advertisement, the second immediately ensures that they are not displayed. You can call later [self setCanDisplayBannerAds:YES];, and he will cope with orientation changes without any problems.

+4
source

, Yimin Rong, , , , SDK. . , .

setCanDisplayBannerAds:, :

, , . , view controller view , . , originalContentView.

, UIViewController .view. .

UIViewController , (, , , ). - UIViewController .view UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth, , , .

[self setCanDisplayBannerAds:YES]; viewDidLoad, UIViewController .view UIView, viewDidLoad, autoresizingMask . , [self setCanDisplayBannerAds:NO]; viewDidLoad .

, [self setCanDisplayBannerAds:YES]; viewDidLoad, , autoresizingMask . :

- (IBAction)TouchUpInside:(id)sender {
    NSLog(@"Touch Up Inside");
    NSLog(@"Original View: %@", self.view);
    [self setCanDisplayBannerAds:YES];
    NSLog(@"New View: %@", self.view);
    NSLog(@"Content View: %@", self.originalContentView);
}

Output: 
2015-02-05 11:32:19.654 ID19658866[12404:3600041] Touch Up Inside
2015-02-05 11:32:19.655 ID19658866[12404:3600041] Original View: <UIView: 0x7f9c42717440; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f9c42717710>>
2015-02-05 11:32:19.666 ID19658866[12404:3600041] New View: <UIView: 0x7f9c42523fb0; frame = (0 0; 375 667); layer = <CALayer: 0x7f9c42524080>>
2015-02-05 11:32:19.666 ID19658866[12404:3600041] Content View: <UIView: 0x7f9c42717440; frame = (0 0; 375 667); autoresize = W+H; layer = <CALayer: 0x7f9c42717710>>

, " " autoresize = W+H;, . , self.view 2- 3- .

, , self.view autoresizingMask, [self setCanDisplayBannerAds:YES];:

self.view.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;

, , .

, ... self.view, [self setCanDisplayBannerAds:YES]; viewDidLoad, autoresizingMask .

+3

, , setNeedsLayout setneedsupdatecontraint ( , , , , ), ? , , . , , , /.

+1

, Yimin Rong . , v., , " ". , , ( ), , . !

+1

All Articles