iOS6中的人像和风景模式
当将我的应用程序更新为iOS6标准时,人像/风景消失了。当我使用Xcode 3编译时,Ir完美工作。但是现在使用最新的Xcode和最新的SDK,旋转消失了,它始终处于纵向模式。无论我在“支持的接口方向”中输入什么内容。我之前用于旋转的代码似乎完全没有效果。 我有这些线。iOS6中的人像和风景模式
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
switch (toInterfaceOrientation) {
case UIInterfaceOrientationPortrait:
case UIInterfaceOrientationLandscapeLeft:
case UIInterfaceOrientationLandscapeRight:
return YES;
default:
return NO;
}
}
如何更改以及如何更改以使其重新工作?
首先,在AppDelegate中写下这个。这是非常IMP
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return (UIInterfaceOrientationMaskAll);
}
那么,对于UIViewControllers,其中只需要纵向模式,写这些功能
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskPortrait);
}
对于UIViewControllers,需要景观也变化屏蔽所有。
- (NSUInteger)supportedInterfaceOrientations
{
return (UIInterfaceOrientationMaskAllButUpsideDown);
//OR return (UIInterfaceOrientationMaskAll);
}
现在,如果您想在方向更改时进行一些更改,请使用此功能。
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
}
编辑:
在很大程度上取决于与控制器UIViewController中嵌入
例如,如果其内部的UINavigationController,那么你可能需要继承的是UINavigationController的覆盖方向。像这样的方法。
subclassed UINavigationController(层次结构的*视图控制器将控制方向。)将它设置为self.window.rootViewController。
- (BOOL)shouldAutorotate
{
return self.topViewController.shouldAutorotate;
}
- (NSUInteger)supportedInterfaceOrientations
{
return self.topViewController.supportedInterfaceOrientations;
}
从iOS 6中,它被赋予的是UINavigationController的不会要求其UIVIewControllers用于定向支持。因此我们需要对它进行子类化。
看起来像一个很好的方法但我很抱歉地说,无论我按下按钮,支持的接口方向,还是不支持,都无法在我的旧项目中工作。而在一个新的项目中,它似乎也不起作用。不知道我在这里做错了什么。 –
检查编辑答案。实际上,我也遇到了类似的问题,这个问题已经得到解决。 – mayuur
将测试你说的话。但与此同时,我得到了旋转工作将这些行设置为委托,self.window.rootViewController = self.navigationController;并根据“按钮选择”旋转工作,但如何使一些ViewController总是在肖像我不明白 –
不知道你的问题是否与我一样,但状态栏的方向正确(横向),并且描述了UIViewController
。 didFinishLaunchingWithOptions: 我在应用程序委托申请改变以下行
//[window addSubview:navigationController.view];
self.window.rootViewController = navigationController;
苹果=>此成本核算我一天半的时间找出来,和很多钱!
如何支撑一个或多个景点的控制器中的应用程序,是肖像主要在iOS6的:
1)中的AppDelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
UINavigationController* ns = (UINavigationController*)self.window.rootViewController;
if (ns) {
UIViewController* vc = [ns visibleViewController];
//by this UIViewController that needs landscape is identified
if ([vc respondsToSelector:@selector(needIos6Landscape)])
return [vc supportedInterfaceOrientations];
}
return UIInterfaceOrientationMaskPortrait; //return default value
}
2)中的UIView控制器(s)表示,需要横向(或纵向+ lanscape等):
//flag method
-(void)needIos6Landscape {
}
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}
3)控制器,以你可以从控制器返回,可在横向旋转 - 这是很重要的,否则他们remaind景观从景观风险投资回报。
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
4)(也许不是必要的,但可以肯定的..) - 您使用,并添加子类导航控制器(S):
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
UIViewController* vc = [self visibleViewController];
if (vc) {
if ([vc respondsToSelector:@selector(needIos6Landscape)]) {
return [vc supportedInterfaceOrientations];
}
}
return UIInterfaceOrientationMaskPortrait;
}
的重要步骤,是要求只定位控制器从你的应用程序,因为在控制器之间的转换,一段时间有一些系统控制器作为根,并将返回不正确的值(这花了我2小时找出,这是它不工作的原因)。
试试这个。它为我工作: http://*.com/questions/10096672/uiwindows-root-view-controller-does-not-rotate-to-landscape-at-app-launch –