Frage

Wie kann ich die Ansicht zu ändern, wenn das iPhone dreht (Änderung Feder des). Aber es sollte geschieht nur in einem einzigen Register! Ich versuchte es mit:

    - (void)viewDidLoad {
 LandscapeViewController *viewController = [[LandscapeViewController alloc]
             initWithNibName:@"LandscapeView" bundle:nil];
 self.landscapeViewController = viewController;
 [viewController release];

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

- (void)orientationChanged:(NSNotification *)notification
{
    [self performSelector:@selector(updateLandscapeView) withObject:nil afterDelay:0];
}

- (void)updateLandscapeView
{
    UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
    if (UIDeviceOrientationIsLandscape(deviceOrientation) && !isShowingLandscapeView)
 {
        [self presentModalViewController:self.landscapeViewController animated:YES];
        isShowingLandscapeView = YES;
    }
 else if (deviceOrientation == UIDeviceOrientationPortrait && isShowingLandscapeView)
 {
        [self dismissModalViewControllerAnimated:YES];
        isShowingLandscapeView = NO;
    }    
}

Aber dann der Landschaft-View erscheint in allen Tabs. (Wenn dieser Code geladen wird einmal). Jede Idee?

War es hilfreich?

Lösung 3

Tanks für Ihre Kommentare! Ich fand eine Abhilfe:

//Remove Observer if not in Landscape
- (void)viewDidDisappear:(BOOL)animated {
    if (isShowingLandscapeView == NO) {
        [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    }   
}

//Add Observer if not in Landscape
- (void)viewDidAppear:(BOOL)animated {
    if (isShowingLandscapeView == NO) {
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:nil];
    }
}

Andere Tipps

Was passiert, ist Ihre Ansicht-Controller die UIDeviceOrientationDidChangeNotification Benachrichtigung erhält, wenn die Drehung ändert, ob es angezeigt wird. Stattdessen versuchen, die integrierten Methoden des UIViewController verwenden, die für die Reaktion auf Drehungen gemeint ist.

http://tinyurl.com/ycb8of2

Dies ist von der Apple-Docs (View-Controller-Programmierhandbuch):

  

Tab Bar-Controller und Ansichtsrotation

     

Tab Bar-Controller unterstützt ein Porträt   Orientierung standardmäßig und nicht   drehen, um eine Querformat   wenn nicht alle der Stammansicht   Controller unterstützt ein solches   Orientierung. Wenn eine Vorrichtung Orientierung   Änderung auftritt, die Registerleiste Controller   Abfragen seiner Reihe von View-Controller.   Wenn einer von ihnen nicht unterstützt   die Ausrichtung, die Registerleiste   Controller nicht ändert seine   Orientierung.

Also, ich bin nicht sicher, dass die Tab Bar-Controller ist so konzipiert, nur für eine einzelne Ansicht zu drehen.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top