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

In Landscape mode, when using Split View multitasking, ad container is wrong. (found fix!) #128

Open CHPraxis opened 8 years ago

CHPraxis commented 8 years ago

So, what's happening is that your code checks if it is landscape or portrait, then if landscape, takes the larger of the height and width as the height. If the user is in landscape, but is using split view (therefore, height is larger than width), the iAd container gets the wrong result and the container starts floating in the middle.

I'm not sure why this logic exists; it seems like, if the user is in landscape, you can simply use the height as height, right? So, I tweaked your code to remove this logic. I commented out two lines and replace them with my lines beneath them. This is the part I modified.

Let me know if there's anything wrong with it? This is in LARSAdController.m .

- (CGRect)containerFrameForInterfaceOrientation:(UIInterfaceOrientation)orientation
                            withPinningLocation:(LARSAdControllerPinLocation)pinningLocation {
    //TODO: Modify height so that the container does not contain any whitespace above ad.
    //This will enable others to add a background to the container (a la weather channel app).
    CGFloat width;
    CGFloat yOrigin = 0.f;

    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);
            yOrigin = parentHeight;
        }
        //width = MAX(parentHeight, parentWidth);
        width = parentWidth;

        self.lastOrientationWasPortrait = NO;
    }
larsacus commented 8 years ago

It's been several years since I wrote this logic, but if I remember correctly, it's because I was having an issue with handling rotation for all cases/platforms. I'm sure a lot of things have changed/been fixed since I wrote this particular section. :smile: Specifically, in iOS 7 or so, your application's window no longer had a transform applied to it, and the window's frame returned the correct values regardless of orientation. This was not always the case in older versions of iOS, though, which is probably what you're seeing here.

:beers:

Querschlag commented 8 years ago

Are there any plans to port the orientation checks to proper trait collection handling and autolayout constraints?

mikemike396 commented 8 years ago

This works great! Thank You for the fix. Any plans to merge this in via PR?