【发布时间】:2013-04-08 05:40:30
【问题描述】:
在我维护的应用程序中,应该在纵向和纵向倒置模式下发生旋转。 (所有旋转都在摘要面板中启用。)
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return interfaceOrientation==UIInterfaceOrientationPortrait || interfaceOrientation==UIInterfaceOrientationPortraitUpsideDown;
}
或
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
无论我尝试什么,我都无法让旋转以准确地运行 i ios 6
到目前为止我尝试过的事情:
-(NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(NSInteger)supportedInterfaceOrientations{
NSInteger mask = 0;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeRight])
mask |= UIInterfaceOrientationMaskLandscapeRight;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationLandscapeLeft])
mask |= UIInterfaceOrientationMaskLandscapeLeft;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortrait])
mask |= UIInterfaceOrientationMaskPortrait;
if ([self shouldAutorotateToInterfaceOrientation: UIInterfaceOrientationPortraitUpsideDown])
mask |= UIInterfaceOrientationMaskPortraitUpsideDown;
return mask;
}
我试着把它放在我的 appdelegate 中:
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
return UIInterfaceOrientationMaskPortraitUpsideDown;
}
但我收到此错误:由于未捕获的异常“UIApplicationInvalidInterfaceOrientation”而终止应用程序,原因:“支持的方向与应用程序没有共同的方向,并且 shouldAutorotate 正在返回 YES”
尝试将其放入我的委托中:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSUInteger orientations = UIInterfaceOrientationMaskAll;
if (self.window.rootViewController) {
UIViewController* presented = [[(UINavigationController *)self.window.rootViewController viewControllers] lastObject];
orientations = [presented supportedInterfaceOrientations];
}
return orientations;
}
我阅读了所有关于它的讨论以及对 shouldAutorotateToInterfaceOrientation 的弃用,但我仍然无法让它发挥作用。
我即将失去它
【问题讨论】:
-
尝试创建一个类别并处理方向。它对我来说工作正常。
-
你能提供一种方法\一些代码吗?
-
删除你的方法并添加代码并让我知道 -(BOOL)shouldAutorotate { return YES; } -(NSInteger)supportedInterfaceOrientations{ 返回 UIInterfaceOrientationMaskAll; }
-
并将应用程序委托方法更改为此 -(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return UIInterfaceOrientationMaskAll; }
-
我仍然无法让它工作。
标签: objective-c cocoa-touch cocoa ios6