Ios4 如何为iphone os 4.2实现splitview?

Ios4 如何为iphone os 4.2实现splitview?,ios4,ipad,Ios4,Ipad,我已经在我的应用程序中使用了自定义splitview 自定义splitview.h文件 @interface CustomUISplitViewController :UISplitViewController { BOOL keepMasterInPortraitMode; BOOL keepMasterInPortraitMode1; } 而.m文件是 -(void) viewWillAppear:(BOOL)animated { keepMasterInPortraitM

我已经在我的应用程序中使用了自定义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下,当应用程序运行时,我只看到一个视图。操作系统版本之间会有什么变化?

我也遇到了同样的问题,我认为这是一个苹果漏洞(我在一个月前提交了它,但没有得到他们的回应)。对我来说,当应用程序在OrienceUIInterfaceOrientation和ScapeRight(3)启动时,它的“细节”视图是空白的。它看起来像这样:。当我将两个视图控制器(例如,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
),则需要在
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;
}

我的申请也有同样的问题。我使用了相同的子类化技术,使主视图和细节在纵向和横向模式下都可见。在4.2版本之前工作得很好,不幸的是,我没有测试Beta版本的可用性

我建议尝试使用优秀的MGSplitViewController()。它是UISplitViewController的开源实现。它唯一的缺点是在Interface Builder中使用起来不太容易,但它包含一个示例项目。从外观上看,它与UISplitViewController相同,但增加了对一些额外功能的支持,例如在运行时拖动拆分位置

只需完全按照UISplitViewController实现它,但在某处添加以下行:

[splitViewController setShowsMasterInPortrait:YES];
这与苹果禁止在其版本中使用的私有API非常相似

//[splitViewController setHidesMasterViewInPortrait:NO];  // Naughty, Naughty, Not allowed by the Apple police

不错。尽管苹果公司忽略了很多其他的缺陷,但这让我毛骨悚然。