我創建了兩個相同的故事板,除了一個包含縱向視圖,另一個包含橫向視圖。Xcode 4.5和iOS 6.x中的故事板方向支持?
我不想使用自動調整大小的遮罩,因爲一些視圖的佈局在縱向和橫向之間完全改變。我手動移動視圖控件上的代碼在過去,但我是一個更簡單的方法在此時間後:)
我發現的最接近的解決方案是從「benyboariu」 - Storyboards orientation support for xCode 4.2?
下面的代碼我使用的是在iOS 5.x上正常工作,但不在iOS 6.x上正常工作。
- (void)updateLandscapeView
{
UIDeviceOrientation deviceOrientation = [UIDevice currentDevice].orientation;
if (deviceOrientation == UIDeviceOrientationUnknown)
{
if ([[UIScreen mainScreen] bounds].size.height > [[UIScreen mainScreen] bounds].size.width)
{
deviceOrientation = UIDeviceOrientationPortrait;
self.appDelegate.isShowingLandscapeView = NO;
}
else
{
deviceOrientation = UIDeviceOrientationLandscapeLeft;
self.appDelegate.isShowingLandscapeView = YES;
}
}
if (UIDeviceOrientationIsLandscape(deviceOrientation) && !self.appDelegate.isShowingLandscapeView)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-Landscape" bundle:[NSBundle mainBundle]];
UIViewController * landscape = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController-Landscape"];
self.appDelegate.isShowingLandscapeView = YES;
[UIView transitionWithView:landscape.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
self.view = landscape.view;
} completion:NULL];
}
else if (UIDeviceOrientationIsPortrait(deviceOrientation) && self.appDelegate.isShowingLandscapeView)
{
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard-Portrait" bundle:[NSBundle mainBundle]];
UIViewController * portrait = [storyboard instantiateViewControllerWithIdentifier:@"RootViewController"];
self.appDelegate.isShowingLandscapeView = NO;
[UIView transitionWithView:portrait.view duration:0 options:UIViewAnimationOptionTransitionCrossDissolve|UIViewAnimationCurveEaseIn animations:^{
self.view = portrait.view;
} completion:NULL];
}
}
在iOS 6.x的調試時,我得到的錯誤是:
終止應用程序由於未捕獲的異常「UIViewControllerHierarchyInconsistency」,理由是:「視圖只能與最多關聯一次一個視圖控制器!查看UIView:0x108276b0; frame =(0 0; 568 268); autoresize = RM + BM;動畫= {position = CABasicAnimation:0x10815c60; bounds = CABasicAnimation:0x1082a5e0; }; layer = CALayer:0x10827710與RootViewController:0x10821f10相關聯。在將此視圖與RootViewController關聯之前清除此關聯:0x961a150。
我通常將視圖控制器與NIB斷開,以解決這種錯誤,但無法通過故事板進行拼接。
任何人有任何想法?
嗨,你對1000和2000是什麼? – Jules