0

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?

4

3 回答 3

2

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."

于 2013-11-03T19:15:22.697 回答
1

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

-(BOOL)shouldAutorotate
{
    return allowAutoRotation;
}
于 2013-11-03T19:15:39.503 回答
1

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

于 2013-11-03T19:15:58.073 回答