views:

125

answers:

2

I use...

-(void)didRotateFromInterfaceOrientation:

... to adapt a view that has been rotated to landscape.

However, I don't know which method to use when the view needs to be rotated back to portrait.

+1  A: 

I use (void)didRotateFromInterfaceOrientation to adapt view when rotation is enabled …

You're missing a colon. The method takes an argument, so it's didRotateFromInterfaceOrientation:.

didRotateFromInterfaceOrientation is another valid selector, but it names a completely different (and probably non-existent and never-called) method.

… but, wich method or how to detect that iphone got back to vertical position in order to readapt view???

As near as I can make out from the documentation, the same method does both jobs. The argument to the method is the old orientation, and self.interfaceRotation is the new rotation.

So, check one of those values (I'd use self.interfaceRotation if I were an iPhone programmer) to see which orientation you're in now, and update your view accordingly.

Peter Hosey
+1  A: 

You can use the same method but include a test to see what the orientation change was.

- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
    switch fromInterfaceOrientation {
        case UIInterfaceOrientationPortrait {
            //... handle roation from portrait
            break;
        }
        case  UIInterfaceOrientationLandscapeLeft {
            //... handle roation LandscapeLeft
            break;
        }
        //.. and so on
    }
}

However, configuring a view for its new orientation should be done in one of the rotation methods that begin with "will". The above method tells the view controller what the previous orientation was. It doesn't send what the current orientation is or will be. The "will" methods allow you adapt the view before the new orientation completes.

TechZen
Great, working, thanks!
Ruthy