0

的选项卡时,只能旋转的一些看法这里是我无法弄清楚如何工作的流程。 (当我声明(工作)时,这意味着在当前状态下,该视图的方向规则正常工作)我如何与一个UINavigationController工作作为一个的UITabBarController

第一次查看:UITabBarController的选项卡的UINavigationController的堆栈上的TableView。

TableView只允许为肖像。 (working) 当您将TableView旋转到横向模式时,会出现一个类似于coverflow的自定义UIView(我将在稍后解释该问题)。

甲选择上的tableview由上推到堆栈一个UIScrollView。

UIScrollView的是允许所有方向。 (工作)

当UIScrollView的是在横向模式和用户打回他们被带到了自定义的UIView是喜欢的CoverFlow和只允许景观。

问题在这里。由于UIScrollView允许完整旋转,因此它允许TableView旋转以及横向旋转。

我有一个方法附加到通知“UIDeviceOrientationDidChangeNotification”,检查自定义视图是否是当前控制器,如果是,并且用户已经旋转回肖像我需要弹出自定义视图并显示表视图。

表视图有转回肖像,这确实是好的,只要用户不会看到它。当我创建自定义动画时,除了一些奇怪的看不见的黑盒子,它似乎随着设备旋转之前,我淡出自定义视图到桌面视图非常好。

此外,为了确保我的tableview将旋转到纵向,我必须允许customview支持所有方向,因为系统查看当前视图(在我的代码中)是否允许该应用旋转到一定的方向。正因为如此,我提出的许多解决方案将在桌面视图重新聚焦时显示自定义视图旋转到纵向。

我的其他问题非常相似。如果您正在查看tableview并旋转customview的模态视图。在此视图上进行选择时,它会将UIScrollview推入堆栈,但由于Tableview仅支持纵向,所以在设备处于横向模式时,UIScrollview以纵向显示。

我该如何克服这些可怕的块?

这是我目前的尝试:

当谈到与工作的UITabBarController系统真的只关心什么tabbarcontroller不得不说的旋转。

目前无论何时报告一个视图加载它支持的方向。

TabBarController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
switch (self.supportedOrientation) { 
    case SupportPortraitOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
     break; 
    case SupportPortraitUpsideDownOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
     break; 
    case SupportPortraitAllOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown); 
     break; 
    case SupportLandscapeLeftOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft); 
     break; 
    case SupportLandscapeRightOrienation: 
     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];    
     return (interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
     break; 
    case SupportLandscapeAllOrientation: 
     [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
     return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); 
     break; 
    case SupportAllOrientation: 
     if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight) { 
      [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES]; 
     }else { 
      //[[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES]; 
     } 
     return YES; 
     break; 
    default: 
     return (interfaceOrientation == UIInterfaceOrientationPortrait); 
     break; 
    } 

}

的代码块是我的UINavigationController的一部分,并且是在响应该通知UIDeviceOrientationDidChangeNotification的方法。它负责弹出customview并显示tableview。有两种不同的版本,最初是针对两种不同版本的SDK,但两者都非常接近解决方案。

第一个在3.0上不支持的原因是由于某些原因,您无法将视图显示并显示为模式视图。不知道这是一个错误还是一个功能。

第二种解决方案工作得非常好,除了我看到一个围绕iphone旋转的外框。

if ([[self topViewController] isKindOfClass:FlowViewController.class]) { 
    NSString *iphoneVersion = [[UIDevice currentDevice] systemVersion]; 
    double version = [iphoneVersion doubleValue]; 
    if(version > 3.0){ //1st solution 
     //if the delivered app is not built with the 3.1 SDK I don't think this will happen anyway 
     //we need to test this 
     [self presentModalViewController:self.flowViewController animated:NO]; 
     //[self toInterfaceOrientation:UIDeviceOrientationPortrait animated:NO]; 
     [self popViewControllerAnimated:NO]; 
     [self setNavigationBarHidden:NO animated:NO]; 
     [self dismissModalViewControllerAnimated:YES]; 
    }else{ //2nd solution 
     DLog(@"3.0!!"); 
     //[self toInterfaceOrientation:UIDeviceOrientationPortrait animated:NO]; 
     CATransition *transition = [CATransition animation]; 
     transition.duration = 0.50; 
     transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
     transition.type = kCATransitionPush; 
     transition.subtype = kCATransitionFade; 

     CATransition *tabBarControllerLayer = [CATransition animation]; 
     tabBarControllerLayer.duration = 0.50; 
     tabBarControllerLayer.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; 
     tabBarControllerLayer.type = kCATransitionPush; 
     tabBarControllerLayer.subtype = kCATransitionFade; 

     [self.tabBarController.view.layer addAnimation:transition forKey:kCATransition]; 
     [self.view.layer addAnimation:transition forKey:kCATransition]; 
     [self popViewControllerAnimated:NO]; 
     [self setNavigationBarHidden:NO animated:NO]; 

    } 
    [self performSelector:@selector(resetFlow) withObject:nil afterDelay:0.75]; 

} 

我接近确信没有解决方案,除了手动旋转,这弄乱了键盘旋转。

任何意见将不胜感激!

谢谢。

回答

0

如果你有一个导航控制器在标签栏控制器,你只想让一些视图旋转我有解决方案。它可能不适合每个人,它可能不是最干净的代码,但到目前为止,它是唯一的解决方案。

此外,此方法假定您不想在第一个视图中看到标签栏,尽管您可以使用popOverControllers实现我的解决方案,但我不确定。

创建的TabBar控制器 创建导航控制器 创建第二个导航控制器,将不会的TabBar控制器 上投放的TabBar控制器 配置方法,将pushViewController首先第一导航控制器:

起飞当前屏幕的屏幕截图。 将该屏幕截图放入UIViewController 推送UIViewController到第二个导航控制器 目前的第二个导航控制器模态 延迟约0.15秒后推动所需的视图控制器到第二个导航控制器的导航堆栈。

现在您的当前控制器已关闭tabBarcontroller并且它的旋转(因为此导航控制器是以模态方式呈现的)独立于tabBarController!

你必须做一些工作才能回到你的第一视图,但这并不难。

这是一个详细的解决方案,我会尝试一段时间获取代码。他们更多的是这个答案,但这应该足以让你开始,如果你需要帮助,让我知道。

0

嗨,你可以尝试这一切:

我使用的每一个针对这一行,所以你可以在任意视图改变首选方向:

- (BOOL)shouldAutorotate 
{ 
    return YES; 
} 

- (NSUInteger)supportedInterfaceOrientations 
{ 
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 
     return UIInterfaceOrientationMaskPortrait; 
    } else { 
     return UIInterfaceOrientationMaskAll; 
    } 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation 
{ 
    return UIInterfaceOrientationPortrait; 
} 

然后,你必须继承的UINavigationController和的UITabBarController ,所以这里是代码:

//cCustomNavigationController.h file 

#import <UIKit/UIKit.h> 

@interface cCustomNavigationController : UINavigationController <UINavigationControllerDelegate> 

@end 

//cCustomNavigationController.m file 

#import "cCustomNavigationController.h" 

@interface cCustomNavigationController() 

@end 

@implementation cCustomNavigationController 

- (BOOL)shouldAutorotate { 
    return [self.visibleViewController shouldAutorotate]; 
} 

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return [self.visibleViewController preferredInterfaceOrientationForPresentation]; 
} 

@end 

//cCustomTabController.h file 

#import <UIKit/UIKit.h> 

@interface cCustomTabController : UITabBarController <UITabBarControllerDelegate> 

@end 

//cCustomTabController.m file 

#import "cCustomTabController.h" 

@interface cCustomTabController () 

@end 

@implementation cCustomTabController 

- (BOOL)shouldAutorotate { 
    return [self.selectedViewController shouldAutorotate]; 
} 

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

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation { 
    return [self.selectedViewController preferredInterfaceOrientationForPresentation]; 
} 

@end 

现在你只需要使用这个类在任何你需要它,即创建您TabBarControler或您的NavigationController

//For the UINavigationController 
UINavigationController *navigationController = [[cCustomNavigationController alloc] init]; 

//For the UITabBarController 
UITabBarController *tabController = [[cCustomTabController alloc] init]; 

现在,您可以以您想要的方式控制所有视图的旋转,我正在使用它,它工作正常。

我希望这可以帮助你,但我不确定这是否是你需要的。

快乐编码。

相关问题