【问题标题】:Single UIViewController Auto-rotation inside UITabBarUITabBar 内的单个 UIViewController 自动旋转
【发布时间】:2016-09-14 06:39:55
【问题描述】:

嗨,我的TabBarViewController 层次结构是这样的。所有带有tabbarViewControllers 都没有navigationController

UIViewController(主视图),当按下它导航到tabBar,基于索引0处的ViewController,用户可以随时使用导航栏中的返回按钮从tabBarViewControllers返回到主页viewController

UITabBarViewController (BaseViewController)
    -ViewController0,(NO Navigation ViewController)
    -ViewController1 (NO Navigation ViewController)
    -ViewController2 (NO Navigation ViewController)
    -ViewController3 (NO Navigation ViewController)
    -ViewController4 (NO Navigation ViewController)

我使用了这种基于ViewControllerTabbar 方法,因为Tabbar 不是Home ViewController

我只想在纵向和横向模式下自动旋转 ViewController2。我的项目仅处于纵向模式。

我尝试了很多类似THIS 的东西,但没有成功。

【问题讨论】:

  • 听不清楚,能详细点吗?
  • @Mr.UB 我已经更新了详细信息
  • 检查这个:stackoverflow.com/questions/39159444/…,如果你明白了什么,请告诉我。
  • @Mr.UB 我明白了你的意思,但是标签栏。我怎样才能使标签栏视图内的单个视图控制器自动旋转而不是应用程序内的其他视图控制器。在我的情况下,在注册或登录和 Tab bar vc 之间有 Home View 控制器

标签: ios objective-c uitabbar


【解决方案1】:

嗨,经过大量研究,我发现了什么,无论是 Tabbar 还是 UIVicontroller

根据我的问题,我的项目处于纵向模式,我只想要单视图控制器自动旋转。以下是对我有帮助的步骤。

1 - 在 App Delegate.h 中

@property (assign, nonatomic) BOOL shouldRotate;

2 - 在 App Delegate.m 中

- (UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(nullable UIWindow *)window  NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED
{
 _shouldRotate = [[NSUserDefaults standardUserDefaults]boolForKey:@"rotateKey"];
 NSLog(@"Did I get to InterfaceOrientation \n And the Bool is %d",_shouldRotate);

 if (self.shouldRotate == YES){
    return UIInterfaceOrientationMaskAll;
 }else{
    return UIInterfaceOrientationMaskPortrait;
 }    
 }

3 - 现在哪个 UIViewController,你想要自动旋转

-(void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:YES];    
  BOOL rotate = YES;
 [[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
 [[NSUserDefaults standardUserDefaults]synchronize];    
}

-(BOOL)shouldAutorotate
{
 return YES;
}

4-Trick Part是

如果您执行上述所有步骤,如果您从当前视图控制器(即横向模式)返回,您的视图控制器将自动旋转。前一个视图控制器将在横向中自动旋转并保持链条。

所以,为了避免这种情况,

如果你从视图控制器 A 转到视图控制器 B。视图控制器是自动旋转的,那么在视图控制器 A 中-

5 - 使用此代码 -

-(void)viewDidAppear:(BOOL)animated
{    
 [super viewDidAppear:YES];

 BOOL rotate = NO;
 [[NSUserDefaults standardUserDefaults]setBool:rotate forKey:@"rotateKey"];
 [[NSUserDefaults standardUserDefaults]synchronize]; 
}
-(BOOL)shouldAutorotate
{    
 return NO;
}

 - (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)toInterfaceOrientation
 {
  return (toInterfaceOrientation == UIInterfaceOrientationPortrait);
 }

#if __IPHONE_OS_VERSION_MAX_ALLOWED < 90000
- (NSUInteger)supportedInterfaceOrientations
#else
- (UIInterfaceOrientationMask)supportedInterfaceOrientations
#endif
{
 dispatch_async(dispatch_get_main_queue(), ^{
    // UI Updates

 });
   return UIInterfaceOrientationMaskPortrait;
 }

【讨论】:

  • AsSalamu Alaikum Imran,无法解决视频通话问题。我找到了一个名为 oovoo SDK 的 api。希望你在其他一些任务。如果您想在您的应用程序中使用视频通话功能,请使用此 SDK。实现起来真的很简单。谢谢。
猜你喜欢
  • 2012-09-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-01-25
  • 1970-01-01
  • 2011-08-16
  • 1970-01-01
相关资源
最近更新 更多