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.














19 comments:

  1. Very informative post on handling shouldAutorotate in iOS 6! The step-by-step explanation is clear and practical, making it easier for developers to implement screen rotation effectively. This kind of technical guidance is highly valuable—thanks for sharing your knowledge. Looking forward to more helpful iOS development tips!



    Generative AI Training In Hyderabad

    ReplyDelete
  2. For those looking to achieve a flawless look for any occasion, professional beauty services can make all the difference. I highly recommend checking out the Beauty Clinic in Hyderabad. With exceptional expertise, personalised care, and advanced techniques, they ensure you look and feel your absolute best, enhancing your natural beauty and boosting your confidence.

    ReplyDelete
  3. Taking care of your skin has never been more crucial, especially with the rise in pollution and hectic urban lifestyles. For those seeking professional dermatological care, the best skin clinic in Hyderabad offers advanced treatments and the expertise of experienced specialists, helping you achieve clear, healthy, and radiant skin.

    ReplyDelete
  4. Understanding how to use should Autorotate with a navigation controller in iOS is very useful for developers working on app orientation handling. Similarly, Oracle Fusion HCM Online Training provides professionals with the right guidance to handle real-world HR scenarios on the cloud with confidence.
    Oracle Fusion HCM Online Training

    ReplyDelete
  5. This article is written in a simple and clear way. It explains difficult concepts in an easy-to-understand manner, and the examples help bring the ideas to life.

    ReplyDelete
  6. It's very nice blog and useful for students and developer.If you're looking for top-quality dental treatment in Nizampet, Nizampet Dentist is your premier destination. Led by the skilled Dr. Sri Lakshmi, the clinic offers comprehensive services—ranging from root canal therapy and dental implants to braces, cosmetic dentistry, and children’s dental care. With modern equipment like 3D imaging, digital X-rays, and a patient-first approach, they deliver comfortable, effective, and personalized care for every smile.
    best dental hospital nizampet

    ReplyDelete
  7. Looking for trusted information on Dental Implant Treatment in Nizampet?
    At Nizampet Dentist, expert implant dentists provide safe, painless, and long-lasting tooth replacement solutions. Dental implants look and work like natural teeth, helping you smile and eat with confidence. Book your consultation today and get a personalized treatment plan for your missing teeth.
    dental implant treatment in nizampet

    ReplyDelete
  8. If you are looking for helpful blogs about saving damaged teeth, this one is worth reading!
    Root Canal Treatment in Nizampet is a safe and effective way to treat infected teeth and relieve pain. At Nizampet Dentist, skilled dentists use modern tools to clean the infection and protect your natural tooth. This treatment helps you avoid tooth removal and keeps your smile healthy for years.
    Root Canal Treatment in Nizampet

    ReplyDelete
  9. Invisalign Providers in Nizampet offer clear, removable aligners that gently move your teeth into the right position. At Nizampet Dentist, skilled orthodontists use digital scans to create a custom treatment plan for each patient. Invisalign aligners are comfortable, almost invisible, and fit easily into your daily routine.
    invisalign providers in nizampet

    ReplyDelete
  10. If you are searching for ways to straighten your teeth without metal braces, invisible aligners are a great choice.
    Invisible Aligners Treatment in Nizampet offers clear, comfortable, and removable trays that gently move your teeth into place.
    At Nizampet Dentist, skilled orthodontists use advanced 3D scans to create custom aligners for your smile.
    invisible aligners treatment in nizampet

    ReplyDelete