UISplitViewController:删除分隔线

发布于 2024-08-27 18:32:37 字数 86 浏览 4 评论 0原文

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

谢谢

When using UISplitViewController on the iPad there's a black vertical divider line between the root and detail view. Is there any way to remove this line?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(13

无悔心 2024-09-03 18:32:37

@bteapot 的出色回答。我对此进行了测试,它有效,甚至消除了主/详细导航栏之间的界限。

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

输入图像描述这里

Excellent answer by @bteapot. I tested this and it works, even gets rid of the line between master/detail nav bars.

You can do this in storyboard by adding the "gutterWidth" key path and the value 0 to the USplitViewController runtime attributes.

enter image description here

染柒℉ 2024-09-03 18:32:37

实际上,我对 appDelegate 中 (Dylan) 的答案进行了一些修改,

我们需要在 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 - 删除圆角来自视图(iPad问题)(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];
}

Actuly I have some modification to answer of (Dylan)'s answer

in the appDelegate we need to add image in spliteview controller rather then window

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]];  

here self is object of AppDelegate.

now Apply the answer of this thread : iPhoneOS SDK - Remove Corner Rounding from views (iPad problem) answer by (abs)

edit in above post's answer is

-(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;
}

** make imgView.hidden to FALSE
declare imgView to the AppDelegate.h file**

and dont forget to call this

-(void)didRotateFromInterfaceOrientation:
        UIInterfaceOrientation)fromInterfaceOrientation
{
    [yourAppDelegate performSelector:@selector(fixRoundedSplitViewCorner) 
          withObject:NULL afterDelay:0];
}
我不会写诗 2024-09-03 18:32:37

chintan adatiya 答案仅覆盖角落和导航栏,但我找到了一个技巧,如何覆盖主视图和详细视图之间的界限。

它并不好,但它就像一个魅力。

  1. 首先创建一个宽 1 像素、高 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

chintan adatiya answer covers only the corners and the navigation bar, but I found an trick how to cover the line between the Master and the Detail view.

It is not nice but it works like a charm.

  1. First create an image which is 1 px wide and 704 pixels high.

  2. In the didFinishLaunchingWithOptions add the following code:

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

And done.

When you want a background image which is continues create 3 images:

  • Master: width: 320, height: 704
  • Detail: width: 703, height: 704
  • Divider:width: 1, height: 704
無心 2024-09-03 18:32:37

第一次发帖,大家好。

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

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

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

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

瞧,享受吧。

First post here, hi everyone.

I discovered how to do it accidentally... when I tried to find why I had LOST the divider line. Here's how to hide it, if you're still interested:

1) In your Detail (right-side) view, make sure you have a subview that spans the whole view.

2) Offset this subview view to (-1, 0).

3) Make sure that the Detail View has its "Clip Subviews" option unchecked.

Voilà, enjoy.

灵芸 2024-09-03 18:32:37

您可以通过在主窗口视图中在其后面设置另一个图像来摆脱它。这是来自应用程序委托 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 自定义绘制的。

You can mostly get rid of it by setting another image behind it in the main window's views. This is from the app delegate 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];

But it still leaves two visual artifacts at the top and the bottom that appear to be custom drawn by the splitviewcontroller.

黯然 2024-09-03 18:32:37

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

Interestingly, In the app that I'm working on I want a black background color for both views in the UISplitViewController. I'd like to change the color of the divider line to white (so that you can see it). Making both background colors black is one way to get rid of (make invisible) the dividing line but that's probably not a solution for most people.

心如狂蝶 2024-09-03 18:32:37

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

splitviewController.view.backgroundColor = UIColor.white

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

Tested on iOS10 (probably will work on iOS9 too).

splitviewController.view.backgroundColor = UIColor.white

it removes divider. Apparently divider is just a gap between master and detail container.

述情 2024-09-03 18:32:37

我环顾四周,得出的结论是,除了创建自己的自定义分割视图之外,没有办法做到这一点。

I looked around for a while, and came to the conclusion that theres no way to do this, other than to create your own custom split view.

带刺的爱情 2024-09-03 18:32:37

我可能会迟到,但是有一个可行的解决方案。它甚至适用于 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;

在< strong>DetailViewController.h 添加以下内容:

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

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

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

运行它并观看魔术;-)

I may be late here, but I DO have a solution that works. It even works for the iOS 8+ splitViewController.preferredDisplayMode = UISplitViewControllerDisplayModeAllVisible; and seamlessly slides in and out when you press the Full Screen toggle button.

Here is the trick :

first Subclass UISplitViewController.m

In the header add the follwing :

@property (strong, nonatomic) UIView *fakeNavBarBGView;

In the viewDidLoad method add the following code :

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;

In the DetailViewController.h add the following :

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

Now here is the final trick : in the DetailViewController.m, add the following in the viewDidLoad method (called every time you click the Master table) :

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

Run it and watch the magic ;-)

呆° 2024-09-03 18:32:37

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

[splitViewController setValue:@0.0 forKey:@"gutterWidth"];

Private API (can cause App Store rejection):

[splitViewController setValue:@0.0 forKey:@"gutterWidth"];
过期以后 2024-09-03 18:32:37

我通过设置第一个 viewController 的视图的 backgroundColor 属性意外地做到了这一点 - 可能是clearColor,我现在不记得了。

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

凶凌 2024-09-03 18:32:37

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文