Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Center position bug on iOS8 #8

Open
umekun123 opened this issue Sep 14, 2014 · 3 comments
Open

Center position bug on iOS8 #8

umekun123 opened this issue Sep 14, 2014 · 3 comments

Comments

@umekun123
Copy link

Hi, thanks for the nice library, the hud is not centered in landscape mode of iPad on iOS8, any idea to fix this?

@umekun123
Copy link
Author

@umekun123
Copy link
Author

This is a quick fix for iOS8 only app.

    case UIInterfaceOrientationLandscapeLeft:
        rotateAngle = -M_PI/2.0f;
        newCenter = CGPointMake([UIScreen mainScreen].bounds.size.height/2, [UIScreen mainScreen].bounds.size.width/2);
        break;
    case UIInterfaceOrientationLandscapeRight:
        rotateAngle = M_PI/2.0f;
        newCenter = CGPointMake([UIScreen mainScreen].bounds.size.height/2, [UIScreen mainScreen].bounds.size.width/2);
        break;

@umekun123
Copy link
Author

This is a quick fir fox iOS9 too.

- (void)positionHUD:(NSNotification*)notification {

    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
    CGRect orientationFrame = [UIScreen mainScreen].bounds;

    if(UIInterfaceOrientationIsLandscape(orientation)) {
        float temp = orientationFrame.size.width;
        orientationFrame.size.width = orientationFrame.size.height;
        orientationFrame.size.height = temp;
    }

    CGFloat activeHeight = orientationFrame.size.height;

    CGFloat posY = floor(activeHeight*0.52);
    CGFloat posX = orientationFrame.size.width/2;

    CGPoint newCenter;
    CGFloat rotateAngle;

    // iOS7 or before
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_7_1) {

        switch (orientation) {
            case UIInterfaceOrientationPortraitUpsideDown:
                rotateAngle = M_PI;
                newCenter = CGPointMake(posX, orientationFrame.size.height-posY);
                break;
            case UIInterfaceOrientationLandscapeLeft:
                rotateAngle = -M_PI/2.0f;
                newCenter = CGPointMake(posY, posX);
                break;
            case UIInterfaceOrientationLandscapeRight:
                rotateAngle = M_PI/2.0f;
                newCenter = CGPointMake(orientationFrame.size.height-posY, posX);
                break;
            default: // as UIInterfaceOrientationPortrait
                rotateAngle = 0.0;
                newCenter = CGPointMake(posX, posY);
                break;
        }

    // iOS8
    } else if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_8_4) {

        switch (orientation) {
            case UIInterfaceOrientationPortraitUpsideDown:
                rotateAngle = M_PI;
                newCenter = CGPointMake(posX, orientationFrame.size.height-posY);
                break;
            case UIInterfaceOrientationLandscapeLeft:
                rotateAngle = -M_PI/2.0f;
                newCenter = CGPointMake([UIScreen mainScreen].bounds.size.height/2, [UIScreen mainScreen].bounds.size.width/2);
                break;
            case UIInterfaceOrientationLandscapeRight:
                rotateAngle = M_PI/2.0f;
                newCenter = CGPointMake([UIScreen mainScreen].bounds.size.height/2, [UIScreen mainScreen].bounds.size.width/2);
                break;
            default: // as UIInterfaceOrientationPortrait
                rotateAngle = 0.0;
                newCenter = CGPointMake(posX, posY);
                break;
        }

    // iOS9
    } else {

        switch (orientation) {
            case UIInterfaceOrientationPortraitUpsideDown:
                rotateAngle = M_PI*2.0f;
                newCenter = CGPointMake(posX, posY);
                break;
            case UIInterfaceOrientationLandscapeLeft:
                rotateAngle = -M_PI*2.0f;
                newCenter = CGPointMake(orientationFrame.size.height/2, orientationFrame.size.width/2);
                break;
            case UIInterfaceOrientationLandscapeRight:
                rotateAngle = M_PI*2.0f;
                newCenter = CGPointMake(orientationFrame.size.height/2, orientationFrame.size.width/2);
                break;
            default: // as UIInterfaceOrientationPortrait
                rotateAngle = 0.0;
                newCenter = CGPointMake(posX, posY);
                break;
        }
    }

    self.hudView.transform = CGAffineTransformMakeRotation(rotateAngle);
    self.hudView.center = newCenter;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant