shannoga
shannoga

Reputation: 19869

viewWillTransitionToSize:withTransitionCoordinator return wrong size in simulator

Hi Iam 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 Size returned is wrong - it returns CGSize(320,568) for all simulators. +n it returns the the width as the height and vice versa.

Thanks

Upvotes: 4

Views: 2517

Answers (1)

mqueue
mqueue

Reputation: 61

I'm getting the correct sizes for the different device simulators, but the x and y seem to be flipped when in landscape mode. I used this hack to correct 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
}

Upvotes: 2

Related Questions