Andrew
Andrew

Reputation: 3892

Force a UIViewController to load a certain orientation

So in my app, I have a navigation stack, where the users can progress through a varity of viewControllers. Some of the views support multiple orientations, while one of the views does not. So my question is, how can I force one specific UIViewController to display only in one orientation. I need this to work both when the view loads for the first time, and when another view is popped off and this view to again visible. Thanks

I implement this two method to control the rotation of the views:

-(void)orientationDidChange:(NSNotification *)notification
-(BOOL)shouldAutoRotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

Thanks

Upvotes: 0

Views: 567

Answers (2)

Bhavin
Bhavin

Reputation: 27235

Answer : shouldAutoRotateToInterfaceOrientation method of UIViewController Class.

This function returns YES if the orientations is supported by your UIView. If you return YES only to the landscape orientation, then the iPhone/iPad will automatically be put in that orientation whenever you load that view.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationLandscape);
}

Upvotes: 0

Rama Rao
Rama Rao

Reputation: 1033

    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

Upvotes: 1

Related Questions