How to layout the originalContentView, when canDisplayBannerAds is YES?

211 views Asked by At

I've always wanted to develop word games, so I have purchased an app template - to learn from the source code.

After I have converted the template to ARC and to Storyboard I would like now to start using iAd in my app.

However when I put self.canDisplayBannerAds = YES; to viewDidLoad of the main VC (where the game board with letters is displayed), then I notice that the method viewDidLayoutSubviews is only called once:

- (void)viewDidLoad
{
    [super viewDidLoad];
    // ... SKIPPED ...   
    self.canDisplayBannerAds = YES;

}

- (void) viewDidLayoutSubviews
{
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone)
    {
        float min = MIN(self.viewWordTableContainer.frame.size.width,
                        self.viewWordTableContainer.frame.size.height);
        NSLog(@"XXX min=%f", min);
        self.constraintWordTableWidth.constant = min;
        self.constraintWordTableHeight.constant = min;
        [_wordTable viewDidLayoutSubviews];
        [self updateLabelWords];
    }
}

And as result the game board with letters is not resized properly and does not occupy the full width (here fullscreen screenshot):

Xcode screenshot

When I remove the line or change it to NO, then viewDidLayoutSubviews is called several times (but surprisingly prints same value of min=375).

I understand that the main view of my VC is being stored away into self.originalContentView but why isn't the viewDidLayoutSubviews being called (as many times as necessary to layout the VC properly)?

I looked a lot in the debugger and also searched at SO (there are only 2 similar questions found) - please recommend me a workaround here.

How does the iAd solution even work? Shouldn't there be some method called by iAd to tell the original view to re-layout itself?

0

There are 0 answers