Pregunta

I am fairly new to iOS development and just inherited bunch of iOS code.

I am trying to start using auto layout and constraints to make it easier to support different screens sizes and iOS versions. I find that once I change storyboard to use an auto layout, background image no longer change when I rotate the iPad into landscape view. I am not sure if this is auto layout preventing this change or is there some other way to switch the background image. I'd appreciate your help.

Here is my rotate method.

- (void)didRotate
{
    UIDeviceOrientation orientation = [UIDevice currentDevice].orientation;

    if ([[UIDevice currentDevice] userInterfaceIdiom] != UIUserInterfaceIdiomPhone)
    {
        if (orientation == UIDeviceOrientationLandscapeLeft || orientation == UIDeviceOrientationLandscapeRight)
        {
            [backgrndView setBackgroundImage:[UIImage imageNamed:@"menu_ipad2.png"] forState:UIControlStateNormal] ;
        }
        else if (orientation == UIDeviceOrientationPortraitUpsideDown|| orientation == UIDeviceOrientationPortrait)
        {
            [backgrndView setBackgroundImage:[UIImage imageNamed:@"menu_ipad.png"] forState:UIControlStateNormal] ;
        }

        [backgrndView sizeToFit];
    }
}
¿Fue útil?

Solución

Adding new left, right and top constraints of value zero to the underlying view (which was a button) fixed the problem.

Otros consejos

I believe the method you're looking to override is didRotateFromInterfaceOrientation: not didRotate

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top