【发布时间】:2013-01-31 12:58:24
【问题描述】:
我的应用程序是基于导航的,主要以纵向运行,但一个视图控制器同时支持纵向和横向。现在的问题是,当我从横向视图控制器推送新视图控制器时,新视图控制器也会以横向模式推送,尽管我希望它处于纵向模式。
此外,当我从横向控制器弹出视图控制器时,弹出的视图控制器将以纵向模式显示。
我不知道我的代码有什么问题。
这是我的代码 sn-p 和用于这些方向支持的信息。
在 info.plist 文件中,我一直支持所有方向,但纵向倒置除外。
我还为导航控制器类别添加了如下类别。
@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
我还创建了一个 UIViewController 子类,它充当所有类的超类。下面是超类的定位方法。
@implementation ParentViewController
- (BOOL)shouldAutorotate{
return NO;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
return UIInterfaceOrientationPortrait;
}
@end
支持横向的方向方法控制器如下。
@implementation LandscapeController
#pragma mark -
#pragma mark Orientation Methods
- (BOOL)shouldAutorotate{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskLandscape;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
@end
提前致谢。
【问题讨论】:
-
我有一个样本可能对你有用。发送你的电子邮件 id 我会发给你
-
感谢 Vidyanand 的回复。这是我的电子邮件 ID:kkumpavat87@gmail.com
-
在我的示例中,第一个视图是纵向,第二个视图是横向,第三个视图又是纵向。删除您的电子邮件
标签: objective-c uiinterfaceorientation autorotate ios6