hmlasnk
hmlasnk

Reputation: 1322

How to stop iPad rotation some occasion?

I have iPad application and it's single view application. That application support on both landscape and portrait views. But it has a button and if that pressed I want to stop the rotation in that screen. After that press it again I want to enable rotation again and user can have to rotate it again. How can I do that?

Upvotes: 0

Views: 96

Answers (3)

user529543
user529543

Reputation:

Depends on which platform need to support. If only one than you have the ideal case, not as me:

#pragma mark -
#pragma mark allow rotations
// iOS 5
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}
// iOS6
- (BOOL)shouldAutorotate
{
    return YES;
}
// iOS6
- (NSUInteger)supportedInterfaceOrientations
{
    return UIInterfaceOrientationMaskAll;
}

That code will allow to rotate. Handle a button action and check a variable and return allowed state for those

Upvotes: 1

woody121
woody121

Reputation: 358

The view controller has the shouldAutorotate function, so just use a boolean variable (in this example "allowAutoRotation", something like:

-(BOOL)shouldAutorotate
{
    return allowAutoRotation;
}

Upvotes: 1

amiller27
amiller27

Reputation: 506

From Apple's website: "If you want to temporarily disable automatic rotation, avoid manipulating the orientation masks to do this. Instead, override the shouldAutorotate method on the topmost view controller. This method is called before performing any autorotation. If it returns NO, then the rotation is suppressed."

Upvotes: 2

Related Questions