我使用以下在网络中找到的代码将画面旋转到风景模式。我不明白他们想做什么。特别是它设定的范围。有人可以解释它在做什么吗?将画面从肖像旋转到风景
if ([[UIApplication sharedApplication] statusBarOrientation] == UIInterfaceOrientationPortrait)
{
CGRect statusBarFrame = [[UIApplication sharedApplication] statusBarFrame];
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:NO];
UIScreen *screen = [UIScreen mainScreen];
CGRect newBounds = CGRectMake(0, 0, screen.bounds.size.height, screen.bounds.size.width - statusBarFrame.size.height);
self.navigationController.view.bounds = newBounds;
self.navigationController.view.center = CGPointMake(newBounds.size.height/2.0, newBounds.size.width/2.0);
self.navigationController.view.transform = CGAffineTransformConcat(self.navigationController.view.transform, CGAffineTransformMakeRotation(degreesToRadian(90)));
self.navigationController.view.center = window.center;
}
你一定会觉得很更好的服务让窗口和UIViewControllers应用变换自己,然后处理任何看法改变了你通过实施具体需要视图控制器上的适当方法。 –
根据我们的要求,我们必须手动完成 – Janaka
手动将转换应用到导航控制器没有什么好的理由。你最终会在脚下射击自己。但是,它正在做的是将转换矩阵应用于90度旋转的视图。如果你这样做,你的边界将会出错(对于新的屏幕高度它们将会太长,对于新的屏幕宽度它们将会太窄)上面的代码更新了边界以适应新的屏幕,将中心重新定位到新的逻辑屏幕中心将应用围绕视图中心的旋转,然后将中心移回屏幕中心 –