18

在 iPad 上使用 UISplitViewController 时,根视图和详细视图之间有一条黑色的垂直分隔线。有什么办法可以去掉这条线?

谢谢

4

13 回答 13

13

@bteapot 的出色回答。我对此进行了测试,它可以工作,甚至摆脱了主/详细导航栏之间的界限。

您可以在情节提要中通过将“gutterWidth”键路径和值 0 添加到 USplitViewController 运行时属性来执行此操作。

在此处输入图像描述

于 2016-11-30T20:06:43.590 回答
10

实际上,我对(Dylan)的回答有一些修改

在 appDelegate 中,我们需要在 spliteview 控制器而不是窗口中添加图像

self.splitViewController.view.opaque = NO;  
imgView = [[UIImageView alloc] initWithImage:
        [UIImage imageNamed:@"FullNavBar.png"]];  
[imgView setFrame:CGRectMake(0, 0, 1024, 44)];  
[[self.splitViewController view] insertSubview:imgView atIndex:0]; 
[[self.splitViewController view] setBackgroundColor:[UIColor clearColor]];  

这里 self 是 AppDelegate 的对象。

现在应用此线程的答案:iPhoneOS SDK - Remove Corner Rounding from views (iPad question)由(abs)回答

在上面的帖子中编辑的答案是

-(void) fixRoundedSplitViewCorner {  
     [self explode:[[UIApplication sharedApplication] keyWindow] level:0];  
}  
-(void) explode:(id)aView level:(int)level 
{

    if ([aView isKindOfClass:[UIImageView class]]) {
        UIImageView* roundedCornerImage = (UIImageView*)aView;
        roundedCornerImage.hidden = YES;
    }
    if (level < 2) {
        for (UIView *subview in [aView subviews]) {
            [self explode:subview level:(level + 1)];
        }
    }

    imgView.hidden = FALSE;
}

** 使 imgView.hidden 为 FALSE 将 imgView 声明到 AppDelegate.h 文件**

别忘了叫这个

-(void)didRotateFromInterfaceOrientation:
        UIInterfaceOrientation)fromInterfaceOrientation
{
    [yourAppDelegate performSelector:@selector(fixRoundedSplitViewCorner) 
          withObject:NULL afterDelay:0];
}
于 2011-09-27T20:12:45.167 回答
6

chintan adatiya 答案仅涵盖角落和导航栏,但我发现了一个技巧,如何覆盖 Master 和 Detail 视图之间的界限。

这不是很好,但它就像一个魅力。

  1. 首先创建一个 1 px 宽和 704 像素高的图像。

  2. 在 didFinishLaunchingWithOptions 添加以下代码:

    UIView *coverView = [[UIView alloc] initWithFrame:CGRectMake(320, 44, 1, 704)];
    [coverView setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"divider_cover.png"]]];
    
    [splitViewController.view addSubview:coverView];
    

并做了。

当您想要一个继续创建 3 个图像的背景图像时:

  • 大师:宽度:320,高度:704
  • 细节:宽度:703,高度:704
  • 分隔线:宽度:1,高度:704
于 2012-01-04T20:57:59.520 回答
5

第一次发帖,大家好。

我意外地发现了如何做到这一点......当我试图找出为什么我丢失了分隔线时。如果您仍然感兴趣,以下是隐藏它的方法:

1)在您的细节(右侧)视图中,确保您有一个跨越整个视图的子视图。

2) 将此子视图视图偏移到 (-1, 0)。

3) 确保详细视图的“剪辑子视图”选项未选中。

瞧,享受吧。

于 2011-04-26T19:54:42.490 回答
3

您可以通过在主窗口的视图中设置另一个图像来摆脱它。这是来自应用程序委托didFinishLaunchingWithOptions

// Add the split view controller's view to the window and display.
splitViewController.view.opaque = NO;
splitViewController.view.backgroundColor = [UIColor clearColor];
[window addSubview:splitViewController.view];
[window insertSubview:bgImageView belowSubview:splitViewController.view];
[window makeKeyAndVisible];

但它仍然在顶部和底部留下两个视觉工件,看起来是由 splitviewcontroller 自定义绘制的。

于 2010-06-21T15:50:19.747 回答
2

有趣的是,在我正在开发的应用程序中,我希望 UISplitViewController 中的两个视图都使用黑色背景色。我想将分隔线的颜色更改为白色(以便您可以看到它)。将两种背景颜色都设为黑色是摆脱(使不可见)分界线的一种方法,但这可能不是大多数人的解决方案。

于 2010-10-30T16:17:26.540 回答
2

在 iOS10 上测试(可能也适用于 iOS9)。

splitviewController.view.backgroundColor = UIColor.white

它删除了分隔符。显然分隔符只是主容器和细节容器之间的差距。

于 2017-02-10T15:33:56.413 回答
1

试试 Matt Gammell 的 MGSplitViewController

http://mattgemmell.com/2010/07/31/mgsplitviewcontroller-for-ipad

于 2011-02-04T07:54:46.957 回答
1

我可能会迟到,但确实有一个可行的解决方案。它甚至适用于 iOS 8+ splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible;并在您按下全屏切换按钮时无缝滑入和滑出。

这是诀窍:

第一个子类UISplitViewController.m

在标题中添加以下内容:

@property (strong, nonatomic) UIView *fakeNavBarBGView;

viewDidLoad方法中添加以下代码:

CGFloat fakeNavBarWidth = 321; // It is important to have it span the width of the master view + 1 because it will not move when the split view slides it's subviews (master and detail)
CGFloat navbarHeight = self.navigationController.navigationBar.frame.size.height + 20;
self.fakeNavBarBGView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, fakeNavBarWidth, navbarHeight)];
self.fakeNavBarBGView.backgroundColor = [UIColor redColor];

// Add Fake navbar to back of view
[self.view insertSubview:self.fakeNavBarBGView atIndex:0];

// SplitView Controller
UISplitViewController *splitViewController = self;
DetailViewController *detailVC = [navigationController.viewControllers lastObject];

detailVC.fakeNavBarSubView = self.fakeNavBarBGView;
detailVC.SVView = self.view;

DetailViewController.h添加以下内容:

@property (strong, nonatomic) UIView *SVView;
@property (strong, nonatomic) UIView *fakeNavBarSubView;

现在这是最后的技巧:在DetailViewController.m中,在 viewDidLoad 方法中添加以下内容(每次单击 Master 表时都会调用):

[self.SVView sendSubviewToBack:self.fakeNavBarSubView];
[self.SVView bringSubviewToFront:self.view];

运行它并观看魔术;-)

于 2014-10-30T10:34:55.777 回答
1

我环顾了一会,得出的结论是,除了创建自己的自定义拆分视图之外,没有其他方法可以做到这一点。

于 2010-06-05T18:44:24.907 回答
1

私有 API(可能导致 App Store 拒绝):

[splitViewController setValue:@0.0 forKey:@"gutterWidth"];
于 2016-01-15T17:54:39.953 回答
-1

I did this accidentally by setting the backgroundColor property of the first viewController's view - possibly to clearColor, I don't remember now.

于 2010-04-10T16:01:21.497 回答
-3

UIManager.put("SplitPaneDivider.draggingColor", new Color(255, 255, 255, 0));

于 2010-11-12T20:52:35.993 回答