Showing posts with label Autorotation. Show all posts
Showing posts with label Autorotation. Show all posts

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



Sunday, November 4, 2012

How to use should autorotate(ios 6) with navigation controller

Keyword: ios6, navigation controller, delegate, rotation, category,should Autoraotate, interface orientation

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

How to use should autorotate(ios 6) with navigation controller

1)Take a project named AutoRotationSample
- project should be of empty application
- uncheck storyboard option.
- follow the below image.















                                                                       
  2) Now add new file of Subclass of UINavigationController






3) Now add two more view controllers named firstViewController and secondViewController
4) open AppDelegate.h and modify the code as follow (modified code is in different color)



#import <UIKit/UIKit.h>
#import "firstViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic,retain) UINavigationController *customNavigation;
@property (nonatomic,retain)firstViewController *first;

@end


5) Open AppDelegate.m and import two files as

    #import "firstViewController.h"
    #import "CustomNavigationController.h"

and synthesize two variables as 

   @synthesize first;
   @synthesize customNavigation;

6) Now modify didFinishLaunchingMethod  as (modified code is in different color)


- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    self.first = [[[firstViewController alloc] initWithNibName:@"firstViewController" bundle:nil]   autorelease];
    self.customNavigation=[[CustomNavigationController alloc ]initWithRootViewController:self.first];
    self.window.rootViewController = self.customNavigation;
    [self.window makeKeyAndVisible];
    return YES;
}



7) Now open CustomNavigationController.m and Implement two methods  as 
  

-(BOOL)shouldAutorotate
{
    return YES;
  
}


-(NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;

}

8) Now every view of your app supports auto rotating.


Note: If you want to auto rotate only one view than

In CustomNavigationController.m modify the code as 



-(BOOL)shouldAutorotate
{
    //return YES;
    return [self.navigationController.topViewController shouldAutorotate];
  
}

in this case you should implement    

 -(BOOL)shouldAutorotate
{
     return YES;
}

in viewcontroller which u want to rotate.