Erzwungene Orientierungsänderung funktioniert manchmal nicht

Wenn in meiner App eine bestimmte Schaltfläche gedrückt wird, sollte die Ansicht die Ausrichtung von Hochformat zu Querformat ändern. Wenn der Benutzer zurückkommt, sollte der Ansichtscontroller wieder auf Hochformat wechseln. Aber manchmal ändert sich die Ausrichtung nicht oder es wird der falsche Ansichtsrahmen verwendet.

Hier ist mein Code

-(void)btnSignClicked:(CustomSignButton *)btn {
    isSignButtonClicked = true;
    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_0) {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"];
    }
    else
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeRight animated:YES];
    }
    selectedWaiverId = btn.customTag;

    SignatureView *obj = [[SignatureView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) delegate:self]; // Most of time got size (568,320) but some time i got (320,568), Don't know why
    [self.view addSubview:obj];
}

#pragma mark - SIGNATUREVIEW DELEGATE
-(void)removeSignatureView:(SignatureView *)signatureView {
    isSignButtonClicked = false;

    if (NSFoundationVersionNumber > NSFoundationVersionNumber_iOS_7_0)
    {
        NSNumber *value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
        [[UIDevice currentDevice] setValue:value forKey:@"orientation"]; // Some time not changed the orientation are view remaining in landscape 
    }
    else
    {
        [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
    }

    [signatureView removeFromSuperview];
    signatureView = nil;

}
#pragma mark
#pragma mark - Rotate screen
-(UIInterfaceOrientationMask)supportedInterfaceOrientations
{
    if (isSignButtonClicked == true)
    {
        return UIInterfaceOrientationMaskLandscapeRight|UIInterfaceOrientationMaskLandscape;
    }
    else
    {
        return UIInterfaceOrientationMaskPortrait;
    }
}
- (BOOL)shouldAutorotate
{
    return YES;
}
-(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    if (isSignButtonClicked == true)
    {
        return (interfaceOrientation == UIInterfaceOrientationLandscapeRight);
    }
    else
    {
        return (interfaceOrientation == UIInterfaceOrientationPortrait);
    }

}

AKTUALISIERE

ManchmalviewWillTransitionToSize Methode wird nicht aufgerufen, daher binde ich auch diese Benachrichtigung ein

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(deviceOrientationDidChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];

Aber manchmal funktioniert das auch nicht.

Antworten auf die Frage(10)

Ihre Antwort auf die Frage