嗨Iam使用此代码支持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).
它返回宽度作为高度,反之亦然.
谢谢
最佳答案 我为不同的设备模拟器获得了正确的大小,但在横向模式下,x和y似乎被翻转.我用这个黑客来纠正它:
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
}