質問

I have several components on my UIView like textfields, labels, tables, buttons. I want to handle device orientation changes. How to make these components arrange at right place automatically? Or do I need to re-frame them?

Please help.

Thanks

役に立ちましたか?

解決

enter image description hereYou may use Autosizing option for the orientation changes.No need to write even a single line of code.

他のヒント

- (void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration {
[self adjustViewsForOrientation:toInterfaceOrientation];
}

- (void) adjustViewsForOrientation:(UIInterfaceOrientation)orientation {
if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {

    // set you subviews,Label button frame here for landscape mode,,
}
else if (orientation == UIInterfaceOrientationPortrait || orientation == UIInterfaceOrientationPortraitUpsideDown) {
    // set you subviews,Label button frame here for portrait-mode,
}
}

//Don't forget to add this Delegate Method

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation{
    // Return YES for supported orientations
    return YES;
}

Hope, this will help you..

Try this

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{


    if(interfaceOrientation == UIInterfaceOrientationPortrait || interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
       // portrait Arrangement
    }       
    else 
    { 
        // Landscape Arrangement
    }
    return (interfaceOrientation == UIInterfaceOrientationLandscapeRight || 
            interfaceOrientation == UIInterfaceOrientationPortrait || 
            interfaceOrientation == UIInterfaceOrientationLandscapeLeft ||
            interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown);
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top