ipup / PPRevealSideViewController

A new container controller to easily push views on side like Path or Facebook
www.ipup.pro
Other
821 stars 194 forks source link

iOS 8b3 - Wrong offset when app starts in landscape. #109

Closed MarcoSpeziali closed 9 years ago

MarcoSpeziali commented 10 years ago

In iOS 8 if the device starts in landscape mode the offset between the left and the center view and between the center and the right one is wrong. I don't actually know if Apple changed something. Anyway I tried to fix the code:

The problem was in the method [PPRevealSideViewController getOffsetForDirection:andInterfaceOrientation:]

The new code is:

if (direction == PPRevealSideDirectionLeft || direction == PPRevealSideDirectionRight) {
    if (PPSystemVersionGreaterOrEqualThan(8)) {
        diff = portraitBounds.size.width - portraitBounds.size.height;
    }
    else  {
        diff = portraitBounds.size.height - portraitBounds.size.width;
    }
}
else if (direction == PPRevealSideDirectionTop) {
    if (PPSystemVersionGreaterOrEqualThan(8)) {
        diff = -(portraitBounds.size.width - portraitBounds.size.height);
    }
    else {
        diff = -(portraitBounds.size.height - portraitBounds.size.width);
    }
}

I was trying to create a pull request but I don't know how to do that! :)

s1m-0n commented 10 years ago

I'm having the same problem - e.g. iPad, launching in landscape mode - offset is wrong. But your code doesn't fix the bug at all. Maybe the GM version changed the behavior again. Have you found any solution?

arodeus commented 10 years ago

Same problem on GM seed.

Had resolved in the same function, but swapping bounds coordinates with the following code:

CGFloat pWidth = portraitBounds.size.width; portraitBounds.size.width = portraitBounds.size.height; portraitBounds.size.height = pWidth;

s1m-0n commented 10 years ago

Thanks! thats also a possible solution! I postet a pull request with commit 3134397 that also fixes the issue in several methods...

arodeus commented 10 years ago

Here the entire method I actually use:

- (CGFloat) getOffsetForDirection:(PPRevealSideDirection)direction andInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    CGFloat offset = [[_viewControllersOffsets objectForKey:[NSNumber numberWithInteger:direction]] floatValue];

    if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
        if (![self isOptionEnabled:PPRevealSideOptionsKeepOffsetOnRotation])
        {
            // Take an orientation free rect
            CGRect portraitBounds = [UIScreen mainScreen].bounds;
            if (PPSystemVersionGreaterOrEqualThan(8)) {
                CGFloat pWidth = portraitBounds.size.width;
                portraitBounds.size.width = portraitBounds.size.height;
                portraitBounds.size.height = pWidth;
            }
            // Get the difference between width and height
            CGFloat diff = 0.0;
            if (direction == PPRevealSideDirectionLeft || direction == PPRevealSideDirectionRight)
                diff = portraitBounds.size.height - portraitBounds.size.width;
            if (direction == PPRevealSideDirectionTop)
                diff = -(portraitBounds.size.height - portraitBounds.size.width);

            // Store the offset + the diff
            offset += diff;
        }
    }

    return offset;
}
dimazen commented 9 years ago

Will it be included? Having the same issue on 8.1

@arodeus thanks for code - fixes the issue

taofang0418 commented 9 years ago

@arodeus

Thanks for your solution