我正在开发应用程序。应用程序的方向是横向的,但是在应用程序运行后应用程序的界面方向会改变界面并旋转。以正确的方式(横向)显示初始屏幕。我正在使用 ios7 该应用程序是 ios5 的代码我认为存在一些已弃用的 api 问题,例如调用 shouldAutorotateToInterfaceOrientation 机器人,因为这在最新的 ios 中不再可用
问问题
420 次
5 回答
1
如果您希望我们所有的导航控制器都尊重顶部视图控制器,您可以使用一个类别,这样您就不必经历并更改一堆类名。
@implementation UINavigationController (Rotation_IOS6)
-(BOOL)shouldAutorotate
{
return [[self.viewControllers lastObject] shouldAutorotate];
}
-(NSUInteger)supportedInterfaceOrientations
{
return [[self.viewControllers lastObject] supportedInterfaceOrientations];
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return [[self.viewControllers lastObject] preferredInterfaceOrientationForPresentation];
}
@end
正如一些评论指出的那样,这是解决问题的快速方法。更好的解决方案是子类 UINavigationController 并将这些方法放在那里。子类也有助于支持 6 和 7。
于 2013-11-08T06:25:19.313 回答
1
您必须在构建时设置 orintatoin 参见图像。
它会解决你的问题。
于 2013-11-08T07:17:44.893 回答
0
我找到了解决方案,我的想法是。第一步通过创建一个类别覆盖我的 UInavigationcontroller
第二步 替换 [self.window addSubview:[navigationController view]]; //老的
使用 [self.window setRootViewController:navigationController]; //新的
于 2013-11-10T07:55:38.810 回答
0
尝试这个:
- (BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeLeft | UIInterfaceOrientationMaskLandscapeRight;
}
编辑 :
请参阅附加链接,可能对您有所帮助。
于 2013-11-08T05:55:06.343 回答
0
在你的 Appdelegate.m 中使用它
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
NSLog(@"Interface orientations");
if([[UIDevice currentDevice]userInterfaceIdiom]==UIUserInterfaceIdiomPad ){
return UIInterfaceOrientationMaskLandScape;
}
else{
return UIInterfaceOrientationMaskPortrait;
}
}
它帮助了我..
于 2014-05-26T10:30:38.303 回答