我有父视图控制器和另一个模态视图控制器。 我在父母的上下文中提出了模态视图控制器:
readingViewController * reading_view_controller = [[readingViewController alloc] initWithNibName:@"readingViewController" bundle:nil];
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self presentModalViewController:reading_view_controller animated:YES];
父viewController不会定位Landscape;所以,我在父viewController中添加了这些方法:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationMaskPortrait;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return (toInterfaceOrientation == UIInterfaceOrientationPortrait || toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
呈现的viewController(模态呈现)应该指向所有可能的方向;所以,我添加了这些方法:
- (NSUInteger)supportedInterfaceOrientations{
return UIInterfaceOrientationMaskAll;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation{
return YES;
}
但是,因为我假设(UIModalPresentationCurrentContext),所呈现的viewController在IOS 5.0中没有定位,而它在IOS 5.0中按预期工作
请问如何解决这个问题?
答案 0 :(得分:1)
如果你有一个基于标签的应用,那么首先在app delegate和self.window.rootviewcontroller-self.tabbarcontroller
中添加一些代码。
@implementation UITabBarController (SK8FASTR2App)
-(BOOL)shouldAutorotate
{
return YES;
}
- (NSUInteger)supportedInterfaceOrientations
{
// your custom logic for rotation of selected tab
if (self.selectedIndex==3){
return UIInterfaceOrientationMaskPortrait;
}
else {
UIInterfaceOrientationMaskPortrait|UIInterfaceOrientationMaskPortraitUpsideDown|UIInterfaceOrientationLandscapeLeft|UIInterfaceOrientationLandscapeRight;
return UIInterfaceOrientationMaskAll;
}
}
@end
before
@implementation AppDelegate
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
更改该课程的方向
-(BOOL)shouldAutorotate
{
return NO;
}
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscapeRight;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeRight;
}
答案 1 :(得分:0)
你应该实施
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation;
例如: -
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationMaskAll;
}