【问题标题】:UITabBarController presentmodal AutoRotate IssueUITabBarController presentmodal AutoRotate 问题
【发布时间】:2013-05-27 12:52:21
【问题描述】:

我有 UITabBarController 的子类来处理轮换问题:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return YES;
}

-(NSUInteger)supportedInterfaceOrientations{
    return [self.selectedViewController supportedInterfaceOrientations];
}

-(BOOL)shouldAutorotate{
    return YES;
}

现在从tabbatcontroller 中的UIViewController 之一,我提出了一个新的UIViewController

MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
UINavigationController *mainNav = [[UINavigationController alloc] initWithRootViewController:mainVC];

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];

在这个新的导航中,我想禁用自动旋转并只允许纵向:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    return NO;
}

-(NSUInteger)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate{
    return NO;
}

但是旋转仍然有效,当我旋转屏幕时,应用程序转到横向屏幕,我该如何解决这个问题?

【问题讨论】:

标签: iphone ios objective-c uitabbarcontroller


【解决方案1】:

您还应该继承UINavigationController 并将以下代码放入您的子类中:

-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // You do not need this method if you are not supporting earlier iOS Versions
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

-(BOOL)shouldAutorotate
{
    return NO;
}

然后,初始化你的子类的一个实例:

MainVC *mainVC = [[MainVC alloc] initWithNibName:@"MainVC" bundle:nil];
MYSubclassedNavigationController *mainNav = [[MYSubclassedNavigationController alloc] initWithRootViewController:mainVC];

radioNav.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:mainNav animated:YES];

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-22
    相关资源
    最近更新 更多