SVStatusHUD
SVStatusHUD copied to clipboard
Center position bug on iOS8
Hi, thanks for the nice library, the hud is not centered in landscape mode of iPad on iOS8, any idea to fix this?
It seems like this change on iOS8 is the reason. http://stackoverflow.com/questions/24150359/is-uiscreen-mainscreen-bounds-size-becoming-orientation-dependent-in-ios8
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;
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;
}