本文介绍了具有UIWindowLevelStatusBar旋转问题的iOS 8/7 UIWindow的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用 UIWindowLevelStatusBar
级别添加UIWindow。它完美地在ipad上以纵向模式工作,但是在旋转设备后它搞砸了。
I'm trying to add a UIWindow with UIWindowLevelStatusBar
level. it works in portrait mode on ipad perfectly but after rotating device its messed up.
在iOS 7.x上所有旋转都很好,除了倒置,在iOS 8上.x只有肖像模式很好,所有其他方向都搞砸了。任何想法如何解决?
on iOS 7.x all rotations are fine except for upside-down, and on iOS 8.x only portrait mode is fine and all other orientations are messed up. any idea how to solve that?
CGRect frame = [UIApplication sharedApplication].statusBarFrame;
self.statusWindow = [[UIWindow alloc] initWithFrame:CGRectMake(frame.origin.x, frame.origin.y, frame.size.width, 20)];
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
CGRect frame = [UIApplication sharedApplication].statusBarFrame;
CGAffineTransform test = [self transformForOrientation:orientation];
[self.statusWindow setWindowLevel:UIWindowLevelStatusBar];
[self.statusWindow setHidden:NO];
- (CGAffineTransform)transformForOrientation:(UIInterfaceOrientation)orientation
{
switch (orientation)
{
case UIInterfaceOrientationLandscapeLeft:
return CGAffineTransformMakeRotation(-DEGREES_TO_RADIANS(90.0f));
case UIInterfaceOrientationLandscapeRight:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(90.0f));
case UIInterfaceOrientationPortraitUpsideDown:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(180.0f));
case UIInterfaceOrientationPortrait:
default:
return CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(0.0f));
}
}
推荐答案
解决方案对于iOS8(需要如上所示的转换):
Solution for iOS8 (need a transform as showed above as well):
UIScreen *screen = [UIScreen mainScreen];
CGRect statusBarFrame = [UIApplication sharedApplication].statusBarFrame;
if ([screen respondsToSelector:@selector(fixedCoordinateSpace)])
{
[self setFrame:[screen.coordinateSpace convertRect:statusBarFrame toCoordinateSpace:screen.fixedCoordinateSpace]];
}
但它不适用于iOS9测试版。
However it does not work for iOS9 beta.
这篇关于具有UIWindowLevelStatusBar旋转问题的iOS 8/7 UIWindow的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!