iphone - UITabBarController presentmodal 自动旋转问题

标签 iphone ios objective-c uitabbarcontroller

我有 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;
}

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

最佳答案

您还应该继承 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];

关于iphone - UITabBarController presentmodal 自动旋转问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16773646/

相关文章:

iphone - 从 iPhone 上的应用内购买交易获取客户信息

ios - 在 UITableViewCell 中追加 UILabel

ios - 如何在字典数组中组合两个字典

objective-c - 调整 NSWindow 大小时自动调整所有 View 的大小

iphone - 将 iPhone 应用移植到 iPad

iphone - 应用程序无法在设备上运行!

ios - 快速导航和多种 View

iphone - 如何在核心数据中对提取进行排序

iphone - UITableViewCell 不断被取消选择

objective-c - 在 iOS 中以 O(1) 时间查找具有唯一前缀的文件