0

Hi my TabBarViewController Hierarchy is like this. All ViewControllers attached with tabbar are without navigationController.

UIViewController (Home View), when Pushed it navigate to tabBar based ViewController at index 0, User Can come back from tabBarViewControllers to home viewController at any time using back button in navigation bar.

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

I used this Approach of Tabbar based ViewController, because Tabbar is not Home ViewController.

I want to auto rotate only ViewController2 in Portrait and Landscape. My Project is only in Portrait Mode.

I tried many thing like THIS, But it not getting.

Community
  • 1
  • 1
ChenSmile
  • 3,401
  • 4
  • 39
  • 69
  • Sounds unclear , can you elaborate more? – Bista Sep 14 '16 at 07:02
  • @Mr.UB i've updated details – ChenSmile Sep 14 '16 at 07:06
  • check this: http://stackoverflow.com/questions/39159444/how-to-get-navigation-based-template-functionality-in-swift-programming/39159793#39159793, let me know if you understand something. – Bista Sep 14 '16 at 07:43
  • @Mr.UB i got ur point but of tab bar. how can i make single view controller inside tab bar view auto rotate not other view controller inside app. In mY case there is Home View controller between signup or login and Tab bar vc's – ChenSmile Sep 14 '16 at 07:47

1 Answers1

1

Hi After lot research What i have found, whether it is Tabbar or UIVicontroller.

As per my Question, My project is in Portrait Mode and I want only single view Controller Auto rotation.Below are the steps, which helped me.

1 - In App Delegate.h

@property (assign, nonatomic) BOOL shouldRotate;

2 - In 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 - Now Which UIViewController, You want Auto rotation,

-(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 is

If you do all above steps, your view controller will get auto rotated, if u come back from current view controller, which is landscape mode. the previous view controller will get auto rotate in landscape and it will keep chain.

So, to avoid this,

If you are going from view Controller A to View Controller B. View Controller is auto- rotation, then in View Controller A-

5 - Use this code -

-(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;
 }
ChenSmile
  • 3,401
  • 4
  • 39
  • 69
  • AsSalamu Alaikum Imran, couldn't help for that video calling issue. I'd found an api named [oovoo SDK](https://developers.oovoo.com). Hope u r in some other task. if u want to go for video call feature in ur apps, use this SDK. It's really simple to implement. Thank you. – Nazik Sep 21 '16 at 06:44