1

我只想在标志 enableRotation=1 时才允许界面更改。我一直在搞乱所有的旋转方法,但一无所获。

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
enableRotation=0;
currentOrientation=fromInterfaceOrientation;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{



NSLog(@"enable rotation call %i\n",enableRotation);
if(enableRotation)
{  
if ((interfaceOrientation== UIInterfaceOrientationPortrait) ||
    (interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    ||(interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)||(interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    )
{

    return YES;
}

        }
else if (interfaceOrientation==currentOrientation){


    return YES;
}
return NO;
}

这就是我用来显示备用视图的内容....

 - (void)orientationChanged:(NSNotification *)notification
{


if (UIDeviceOrientationIsPortrait(deviceOrientation))
{
    [self performSegueWithIdentifier:@"DisplayAlternateView" sender:self];
    isShowingLandscapeView = NO;
  //  enableRotation=0;
    NSLog(@"Rotation disabled\n");

}
else if (UIDeviceOrientationIsLandscape(deviceOrientation) &&
         !isShowingLandscapeView)
{

    [self dismissViewControllerAnimated:YES completion:nil];
    isShowingLandscapeView = YES;
 //   enableRotation=0;
    NSLog(@"Rotation disabled Change to Landscape\n");

}

}

4

1 回答 1

1

你应该摆脱这种!isShowingLandscapeView状况。这可能会导致问题,因为您可能会多次收到该通知。实际上完全摆脱了布尔值。你不需要它。您始终可以使用[UIDevice currentDevice].orientation或获取方向[UIApplication sharedApplication].statusBarOrientation

事实上,您无需注册此通知期。您可以使用-(void)willRotateToInterfaceOrientation: (UIInterfaceOrientation)orientation duration:(NSTimeInterval)duration适当地更改视图。

此外,您还应该进行此更改:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if(enableRotation)
        return YES;
    else
        return NO;
}
于 2012-06-19T19:37:53.933 回答