larsacus / LARSAdController

Lightweight ad mediation for iOS to properly manage multiple ad networks dynamically including iAd and Google ads.
http://theonlylars.com/blog/2013/01/10/stupid-easy-ads-with-larsadcontroller-3-dot-0/
MIT License
269 stars 60 forks source link

Ads in UITabBarController #31

Closed nziebart closed 11 years ago

nziebart commented 11 years ago

Hi,

I found that the AdContainerView frame is not getting set properly when added to a UIViewController that is within a UITabBarController. The ads display in portrait mode, but not landscape.

To fix this problem, I made a simple change to containerFrameForInterfaceOrientation:withPinningLocation: in LARSAdController.m: (I flipped the yOrigin and width assignments)

if (UIInterfaceOrientationIsLandscape(orientation)) {
        TOLLog(@"View is landscape");

        if (pinningLocation == LARSAdControllerPinLocationBottom) {
            yOrigin = CGRectGetHeight(self.parentView.frame);
        }
        width = CGRectGetWidth(self.parentView.frame);
        self.lastOrientationWasPortrait = NO;
    }
larsacus commented 11 years ago

What do the logs show?

larsacus commented 11 years ago

Also, unfortunately, your change breaks all implementations that I have, including the example project in the repo.

larsacus commented 11 years ago

Hmm.. so this is interesting. If I put my view controller in a tab bar controller of a navigation controller and not just a bare view controller, the height/width is reported as "correct". When in a bare view controller, it is being reported as backwards when in landscape (like a window frame is reported). I changed the layout logic to look like this and it seems to be working:

    CGFloat parentWidth = CGRectGetWidth(self.parentView.frame);
    CGFloat parentHeight = CGRectGetHeight(self.parentView.frame);

    if (UIInterfaceOrientationIsLandscape(orientation)) {
        TOLLog(@"View is landscape");

        if (pinningLocation == LARSAdControllerPinLocationBottom) {
            yOrigin = MIN(parentHeight, parentWidth);
        }
        width = MAX(parentHeight, parentWidth);
        self.lastOrientationWasPortrait = NO;
    }
    else{//portrait
        TOLLog(@"View is portrait");

        if (pinningLocation == LARSAdControllerPinLocationBottom) {
            yOrigin = MAX(parentHeight, parentWidth);
        }
        width = MIN(parentHeight, parentWidth);
        self.lastOrientationWasPortrait = YES;
    }
nziebart commented 11 years ago

I tried the change you posted and it works for me. I should have mentioned, I am using a UISplitViewController within a tab bar controller (the ads are added to the split view controller)

larsacus commented 11 years ago

Ill go ahead and post this change. That's an interesting config that I haven't tried.