views:

113

answers:

3

How to rotate from portrait to landscape? What would I have to implement? And what must I do that my views resize to the new width?

+2  A: 

Hi

The below method "return yes" will make orientation change if it is "return NO" the orientation will not change.

- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orientation 
{

 return YES;

}

All the best.

Warrior
This means it will auto-rotate to all orientations, which is the goal for apps now. If you wanted to restrict the orientations, you can return whether the given orientation (the argument) is equal to one of [these](http://developer.apple.com/iphone/library/documentation/uikit/reference/UIApplication_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006728-CH3-SW5).
paxswill
A: 

To answer the second part of your question, you can add logic to resize or position views by overriding the -willRotateToInterfaceOrientation:duration: method, e.g.:

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
    if (toInterfaceOrientation == UIDeviceOrientationUnknown || toInterfaceOrientation == UIDeviceOrientationFaceUp || toInterfaceOrientation == UIDeviceOrientationFaceDown) {
        // do something here for these orientations
    }
    else {
        // do something else for the remaining orientation types
    }
}
Alex Reynolds
A: 

if your view controller is not the top-layer view controller, you must pass the message willRotateToInterfaceOrientation:duration: from the top-layer view controller.. your view controller might not receive the message...

at my top-layer view controller's willRotateToInterfaceOrientation:duration:, i included this line... (frameViewController is my 2nd level view controller)

if (frameViewController)
        [frameViewController willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
Yit Ming