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 に答える