Rotate iPad TabBar subclass

http://cocoanotes.wordpress.com/2008/10/29/how-to-rotate-a-uitabbarcontroller/

Add a new class to the project. Right-click the Classes group in the Groups & Files pane and choose Add… -> New File… Choose an NSObject subclass in the Cocoa Touch Classes group and name it MyTabBarController.

Open the MyTabBarController.h file and change it in this way:

#import <UIKit/UIKit.h>

@interface MyTabBarController : UITabBarController {

}
@end

Notice that I am subclassing UITabBarController. Now, edit the MyTabBarController.m file and add the following method:

– (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}

Save it. We have simply created a subclass of UITabBarController able to rotate. Now, we need to tell Interface Builder to use this class, instead of its parent.

Double-click the MainWindow.xib file and select the Tab Bar Controller object in the MainWindow.xib window. Open the Identity Inspector and change the class name to MyTabBarController. Save it and close Interface Builder. Go back to Xcode and build and run. Now, if you try to rotate the view…… it works.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s