0

我的方向设置为横向,iphone 模拟器加载并以横向模式启动我的应用程序。从 ios6 开始,上面的代码以纵向模式而不是横向模式加载图片。请指教。

编辑:问题从这里开始:

- (void)viewDidLoad {
    [super viewDidLoad];
    [self.view setBackgroundColor:[[UIColor alloc] initWithPatternImage:[UIImage imageNamed:@"480x320-background.png"]]];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)anInterfaceOrientation{
    return anInterfaceOrientation==UIInterfaceOrientationLandscapeLeft || anInterfaceOrientation==UIInterfaceOrientationLandscapeRight;
}
4

4 回答 4

1

在 iOS6shouldAutorotateToInterfaceOrientation中已弃用。您必须使用supportedInterfaceOrientationsshouldAutorotate

于 2012-12-31T10:32:14.500 回答
0

要修复 IOS6 中的自动旋转问题,请执行以下操作:

内部AppDelegate.m文件

添加以下内容

if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
{
    // Note : addSubView doesn't work on IOS6
    [window addSubview: viewController.view];
}
else
{
    // For IOS6, use this method
    [window setRootViewController:viewController];
}

代替

[window addSubview: viewController.view];

内部RootViewController.m文件

// 对于 IOS6,使用supportedInterfaceOrientations&shouldAutorotate代替shouldAutorotateToInterfaceOrientation

- (NSUInteger) supportedInterfaceOrientations
{
  return UIInterfaceOrientationMaskLandscape;   
}

- (BOOL) shouldAutorotate 
{
  return YES;
}
于 2012-12-31T11:47:54.370 回答
0

在 iOS 6 中,旋转方式发生了变化。您应该实现此方法,并返回 YES。

- (BOOL) shouldAutorotate 
{
  return YES;
}
于 2012-12-31T11:52:13.797 回答
0

那是什么解决了我的问题:在didFinishLaunchingWithOptions [window setRootViewController:headiPhone];

于 2013-01-01T06:48:14.950 回答