Ramesh R C
Ramesh R C

Reputation: 672

Rotate UIWindow in iPad

am creating a application which is support all type of orientation, i added one UIView on the UIWindow.but on rotating the device the view which is added on the Window is not rotating. the view always showing default (Portrait). please help me to fix this problem ... Thanks in advance

Upvotes: 0

Views: 953

Answers (2)

Mark Pervovskiy
Mark Pervovskiy

Reputation: 1123

UIView doesn't handle rotations, UIViewController does. So, all you need is to create a UIViewController, which implements shouldAutorotateToInterfaceOrientation and sets this controller as a rootViewController to your UIWindow

Something like that:


    - (void) makeWindow
    {
        UIViewController * vc = [[[MyViewController alloc] init] autorelease];

        UIWindow * window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [window setRootViewController:vc];
        [window makeKeyAndVisible];
    }


    @interface MyViewController : UIViewController

    @end

    @implementation MyViewController

    - (void)viewDidLoad
    {
        [super viewDidLoad];
        self.view.backgroundColor = [UIColor redColor];
        //your view initialization here
    }


    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    {
        return YES;
    }
    @end

Upvotes: 0

Saurabh
Saurabh

Reputation: 22893

You need to add a UIViewController on your UIWindow.

Upvotes: 1

Related Questions