4

嗨,我使用此代码在 iPhone 6 上支持 splitViewController:

- (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];
}

问题是返回的大小是错误的 - 它为所有模拟器返回 CGSize(320,568)。+n 它返回宽度作为高度,反之亦然。

谢谢

4

1 回答 1

2

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
}
于 2014-11-21T22:54:59.573 回答