ViewWillTransitionToSize: withTransitionCoordinator returns wrong size in simulator

Hi I am using this code to support splitViewController on iPhone 6:

- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id <UIViewControllerTransitionCoordinator>)coordinator
{
    self.forcedTraitCollection = nil;
    if (size.height == 320.0 || size.width == 320.0)
    {
        self.forcedTraitCollection = nil;
    }
    else
    {
        self.forcedTraitCollection = [UITraitCollection traitCollectionWithHorizontalSizeClass:UIUserInterfaceSizeClassRegular];
    }

    [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator];
}

      

The problem is that the returned size is wrong - it returns CGSize (320 568) for all simulators. + n returns width as height and vice versa.

thank

+3


source to share


1 answer


I am getting the correct dimensions for different device simulators, but the x and y seem to be flipped in landscape mode. I used this hack to fix it:



let mainScreen = UIScreen.mainScreen()
let screenSize = mainScreen.applicationFrame // CGRect screen bounds
var width = size.width
if screenSize.width == size.width {
    // size must be wrong or flipped
    width = size.height
}

      

+2


source







All Articles