我在我的应用程序中使用了自定义splitview。
自定义splitview .h文件
@interface CustomUISplitViewController :UISplitViewController {
BOOL keepMasterInPortraitMode;
BOOL keepMasterInPortraitMode1;
}
和.m文件是
-(void) viewWillAppear:(BOOL)animated {
keepMasterInPortraitMode1=keepMasterInPortraitMode;
if(keepMasterInPortraitMode1 == NO) {
if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft || self.interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
UIViewController* master = [self.viewControllers objectAtIndex:0];
UIViewController* detail = [self.viewControllers objectAtIndex:1];
[self setupPortraitMode:master detail:detail];
}
}
if (self.interfaceOrientation == UIInterfaceOrientationPortrait || self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
UIViewController* master = [self.viewControllers objectAtIndex:0];
UIViewController* detail = [self.viewControllers objectAtIndex:1];
[self setupPortraitMode:master detail:detail];
}
}
}
- (void)setupPortraitMode:(UIViewController*)master detail:(UIViewController*)detail {
//adjust master view
CGRect f = master.view.frame;
f.size.width = 220;
f.size.height = 1024;
f.origin.x = 0;
f.origin.y =0;
[master.view setFrame:f];
//adjust detail view
f = detail.view.frame;
f.size.width = 548;
f.size.height = 1024;
f.origin.x = 221;
f.origin.y = 0;
[detail.view setFrame:f];
}
这在iOS4.0下正常工作但在4.2下我在应用运行时只看到一个视图。 OS版本之间可能有什么变化?
答案 0 :(得分:0)
我遇到了同样的问题而且我认为这是一个苹果错误(我在一个月前提交了它而没有得到他们的回复。)对我来说,这是特别是应用程序启动时空白的“详细信息”视图在orientation UIInterfaceOrientationLandscapeRight(3)。它看起来像这样:http://d.pr/cGcU。当我将两个视图控制器之一(例如,RootViewController)限制为仅横向时,会发生这种情况:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
有了这个,在详细视图初始化期间会发生以下情况:
2010-11-15 20:17:47.792 MultipleDetailViews[96250:207] firstDetailViewController willAnimateRotationToInterfaceOrientation: 3 (landscape)
2010-11-15 20:17:47.792 MultipleDetailViews[96250:207] self.view.hidden is: 0
2010-11-15 20:17:47.799 MultipleDetailViews[96250:207] rotating...
2010-11-15 20:17:47.848 MultipleDetailViews[96250:207] firstDetailViewController didRotateFromInterfaceOrientation
2010-11-15 20:17:47.849 MultipleDetailViews[96250:207] self.view.hidden is: 1
出于某种原因,细节视图会在旋转到方向3时神秘地隐藏起来。直到Apple修复此错误(3.2中没有出现),我的解决方法是在详细视图控制器中重写以下方法, - 旋转完成后显示视图:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
self.view.hidden = NO;
}
编辑:如果您的详情视图不是splitViewController.view
的直接子视图(例如,您使用的是UINavigationController
),则需要设置hidden
}在UISplitViewController
:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
// Make sure you set splitViewController via an outlet or get it via your AppDelegate
for (UIView *splitViewChild in splitViewController.view.subviews)
splitViewChild.hidden = NO;
}
答案 1 :(得分:0)
我的应用程序遇到了完全相同的问题。我使用了相同的Subclassing技术,在Portrait和Landscape模式下都可以看到Master和Detail。工作得很好,直到4.2,遗憾的是我没有测试Beta版本何时可用。
我建议尝试优秀的MGSplitViewController(http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad)。它是UISplitViewController的开源实现。唯一的缺点是它在Interface Builder中使用起来并不那么容易,但它包含一个示例项目。在视觉上它与UISplitViewController相同,但增加了对几个附加功能的支持,例如在运行时拖动分割位置。
完全按照UISplitViewController实现它,但在某处添加以下行:
[splitViewController setShowsMasterInPortrait:YES];
这与Apple禁止在其版本中使用的私有API非常相似。
//[splitViewController setHidesMasterViewInPortrait:NO]; // Naughty, Naughty, Not allowed by the Apple police