【发布时间】:2015-01-14 14:08:47
【问题描述】:
我正在尝试添加具有UIWindowLevelStatusBar 级别的 UIWindow。它可以在 ipad 上完美地以纵向模式工作,但是在旋转设备后它就搞砸了。
在 iOS 7.x 上,所有旋转都很好,除了倒置,在 iOS 8.x 上,只有纵向模式很好,所有其他方向都搞砸了。知道如何解决吗?
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));
}
}
【问题讨论】:
-
这是一种高度随机的方式来处理方向支持。您甚至根本不应该考虑转换任何东西,因为只要您正确设置了
rootViewController属性,UIWindow就可以并且将为您处理所有事情。 -
您的代码中缺少某些内容,显示与您的 statusWindow 相关的所有代码。
-
为澄清起见,此代码将在状态栏上设置另一个 uiwindow。所以没有rootviewcontroller。如果我不转换 uiwindow 保持纵向模式并且不会在 iOS 7 和 iOS 8 上旋转,因此必须手动旋转。如果您知道更好的方法,请分享。