Tuesday, November 27, 2012

How To Use shouldAutoRotate With Tab Bar controller in iOS6

Keyword: ios6, tab bar controller, delegate, rotation, category,should Autoraotate, interface orientatio


 Get contacts of all your emergency needs on single tap. Download Quick-Finder for iPhone

How To Use shouldAutoRotate With Tab Bar controller in iOS6



To Support tabBarController auto Rotation in iOS6. You need to make category for that.


Add new file in you project named UITabBarController+autoRotate. File should be subclass of NSObject.




Modified the code of  UITabBarController+autoRotate.h as 




#import <UIKit/UIKit.h>

@interface UITabBarController (autoRotate)<UITabBarControllerDelegate>

-(BOOL)shouldAutorotate;
- (NSUInteger)supportedInterfaceOrientations;

@end


And Modified the code of  UITabBarController+autoRotate.m as 






#import "UITabBarController+autoRotate.h"
#import "AppDelegate.h"// 


@implementation UITabBarController (autoRotate)

-(BOOL)shouldAutorotate {
    
    AppDelegate *delegate= (AppDelegate*)[[UIApplication sharedApplication]delegate];
    return [delegate.tabBarController.selectedViewController shouldAutorotate];
}


- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskAll;
}

@end

Thats it.

Note: you may have to change name of AppDelegate With your Project AppDelegate name.

Feel free to use comment section



No comments:

Post a Comment