matthias_buehlmann
matthias_buehlmann

Reputation: 5061

Deactivate automatic screen rotation temporarily

For our iPad application, I would like to allow for auto rotation of the screen in landscape mode (not portrait) to support both possible orientations. However, there are portions of our application during which the user needs shake and move the iPad into directions and orientations, that will trigger the auto rotation feature but should not.

is it possible to de- and re-activate the autoorientation, such that the orientation will be locked when entering this section of the app and unlocked when exiting?

Upvotes: 4

Views: 695

Answers (1)

Roger
Roger

Reputation: 399

if the specific section means another view controller, YES it is possible

just add this line of code to the controller ..

// which orientation that this view controller support
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskPortrait;
}

// prevent rotation
- (BOOL)shouldAutorotate
{
    return NO;
}

// after present this view controller, which orientation do you prefer ?
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
    return UIInterfaceOrientationPortrait;
} 

Upvotes: 1

Related Questions