Skip to content

Center position bug on iOS8 #8

Open

Description

@umekun123

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

Activity

  1. umekun123 commented on Sep 14, 2014

    @umekun123
    Author
  2. umekun123 commented on Sep 14, 2014

    @umekun123
    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;
    
  3. umekun123 commented on Jan 22, 2016

    @umekun123
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions