Pergunta

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?

Foi útil?

Solução

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.

Outras dicas

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
    }
}

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];
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top